

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to C++ programming, focusing on its advantages, compilation process, and basic language features. It covers topics such as variables, input, and the role of tokens and operators. Students will also learn about the different data types and their sizes and ranges.
What you will learn
Typology: Study notes
1 / 25
This page cannot be seen from the preview
Don't miss anything!
2022
Instructor 1
Compiled Languages and C++
Hello World
Basic Language Features
Variables
Input
Source File
Source File
Object File
Object File
Executable Program inMemory
Linker Libraries
OS
Compiler
Compiler
Steps:
Steps:
Steps:
Steps:
Click “New Project”
// A Hello World program
int main () { std :: cout << " Hello , world !\ n "; return 0; }
Tokens are the minimals chunk of program that have meaning to the compiler – the smallest meaningful symbols in the language. Our code displays all 6 kinds of tokens, though the usual use of operators is not present here:
Token type Description/Purpose Examples
Operators Mathematical or logical operations
Punctuation/Separators Punctuation defining the structure of a program
Whitespace Spaces of various sorts; ignored by the compiler
Spaces, tabs, newlines, comments
● Indicates that everything following it until the end of the line is a comment: it is ignored by the compiler.
● Another way to write a comment is to put it between /* and */
e.g. x = 1 + /sneaky comment here/
● A comment of this form may span multiple lines. Comments exist to explain non-obvious things going on in the code. Use them: document your code well!
● cout << : This is the syntax for outputting some piece of text to the screen. We’ll discuss how it works later!
● Namespaces: In C++, identifiers can be defined within a context – sort of a directory of names – called a namespace. When we want to access an identifier defined in a namespace, we tell the compiler to look for it in that namespace using the scope resolution operator (::). Here, we’re telling the compiler to look for cout in the std namespace, in which many standard C++ identifiers are defined.
A cleaner alternative is to add the following line below line 2: using namespace std ;
This line tells the compiler that it should look in the std namespace for any identifier we haven’t defined. If we do this, we can omit the std:: prefix when writing cout. This is the recommended practice.
● Strings: A sequence of characters such as Hello, world is known as a string. A string that is specified explicitly in a program is a string literal.
● Escape sequences: The \n indicates a newline character. It is an example of an escape sequence – a symbol used to represent a special character in a text literal. Here are all the C++ escape sequences which you can include in strings:
● return 0 indicates that the program should tell the operating system it has completed successfully. This syntax will be explained in the context of functions; for now, just include it as the last line in the main block. 4
Note:
Every statement ends with a semicolon (except preprocessor commands and blocks using {}). Forgetting these semicolons is a common mistake among new C++ programmers.
Note: Not every statement is an expression. It makes no sense to talk about the value of an #include statement, for instance.