/* First Program in C++ to display text on

screen */


#include <iostream>

using namespace std;

int main ( )

{


cout<< “ Welcome to C++” ;

return o;

}

/* ... */

• Line begin with /* and end with */ indicating that

these two lines are comment.

• Comments are used to document programs and

improve readability.

• Comments helps other people to understand your

program.

• Comments do not cause the computer to perform

any action and are ignored by compiler when

program is run.

Comments in C++?

Single line comment

– // (double slash)

– Termination of comment is by pressing enter

key


Multi-line comment

/*....

.......*/

This can span over to multiple lines

# include

• Line begins with # is called “pre process directives”.

• Not part of our program, it is instruction to compiler.

• Tells the compiler to “include” the contents of a file.

iostream (input output stream)

header/include file:

Ø iostream is an example of a header file

Ø The pre-processor directive #include tells the

compiler to add file iostream to the source file before

compiling

Ø iostream is concerned with basic input/output

operations and contains declarations that are

needed by the cout and << (insertion operator)

Ø Without iostream compiler won’t recognize cout and

<< and will generate an error message

Ø iostream file can be found in the include directory of

C++ compiler

Header files?

• The files that are specified in the include

section is called as header file

• These are precompiled files that has some

functions defined in them

• We can call those functions in our program by

supplying parameters

• Header file is given an extension .h

• Source file is given an extension .cpp

main( )  ?

main( ) is part of every C++ program.

• ( ) parenthesis after main indicates that main is a

“function”.

• All C/C++ programs must have at least one

function i.e., main.

• main is the point from where the program

execution begins.

Delimiter { } ?

• Left brace { indicates the starting of every

function.


• Right brace } indicates the ending of every

function.

cout<< ?

The statement


cout << “Welcome to C++”;


• causes the phrase in quotation-marks to be displayed

on the screen.

cout is predefined object that redirects the stream

(flow of data) to output device. cout is predefined in

C++ library.

• The operator << is called the insertion or put-to

operator. It directs the contents of the variable on its

right to the object on its left.

Semicolon ; - statement terminator ?

• Tells the compiler where a given statement ends.


• Every statement must end with semicolon.


• Also known as statement terminator.

Saving the Program in C++ Language?

• After you have typed in the source file for the

program, you should save it on your disk or hard

disk. To do this, select the Save option from the File

menu.

• The file extention of .cpp is necessary

– For example: program.cpp, first.cpp, ee001.cpp

Compiling and Making an .exe file ?

• After you have written the source file for your program, you

need to turn it into an executable file. The compiler, which

is a part of the IDE, translate the source code into another

file known as ( .obj ) Object file, consisting of the machine

language.


• The linker then links the entire necessary object files

together to produce a final executable program with the

extension ( .exe)

Processing a High Level Language program?

1. Use an editor or a word processor program to

enter each line of the source program into

memory and to save it on disk as a source file.

2. Use a compiler program to translate the source

program into machine language. If there are

syntax errors i.e., errors in grammar, the

compiler displays these errors on the monitor.

Use the editor program to correct the errors by

editing and resaving the source program.

3. When the source program is free of syntax errors, the

compiler saves its machine language translation as an

object program.

4. The linker program combines your object program

with additional object files that may be needed for

your program to execute and saves the final machine

language program an executable file on the disk.

5. The loader program places the executable file in the

memory, ready for execution.

<stdio.h> ?


• Name of standard library file, stands for STanDard Input

Output.

• .h is extension called header file. Header file contains the

information used by compiler when compiling library

function.

• Stdio.h contains the functions that we want to use (e.g in our

program printf( ) function).