You are on page 1of 15

Tuesday, September 13, 2011

I hear and I forget, I see and I remember, I do and I understand


-Chinese Proverb

C++ programming language.


High level language

What does the computer understand?

What do we need here?

myprogram.c
#include <iostream> using namespace std;
int main() { cout<<Hello\n; return 0; }

It is human-readable

myprogram.o

machine-readable

Compiler Source code Object code

Creating Executable code

Compiler

Preprocessor

Linker

#include <iostream> using namaespace std; int main( ) { cout <<"Welcome to C++"; return 0; }

iostream is the name of library that contains definition of routines that handle input and output.

Comments have two forms in C++

//Single line comments /*Multi-line comments*/


/* comments ignored by compiler */

Comments have two forms in C++

//I am a Single line comment


/*I am a Multi-line comment and I can span multiple lines This is my line number 5 */

#include <iostream> using namespace std; int main( ) { cout <<"Welcome to C++"; return 0; //this is a simple program }//end of main block

int main(){cout <<"Welcome to C++";return 0;}

Bad programming style!

Statements end with a semi-colon ;

Omitting a semicolon is a syntax error. Other errors could be: mis-typing a keyword omitting braces or parenthesis forgetting << operator in cout Compiler can catch such errors.

You might also like