Documente Academic
Documente Profesional
Documente Cultură
Object code
An Introduction to Programming
with C++, Fifth Edition
Header File
To include header
files in our program
Preprocessor
Directives
Angle or pointed
brackets
h stands for header file
1
Return type of main
function. It is used
to determines
whether the
program is
executed
successfully or not.
Void means nothing
Body
Begin
#include<iostream.h>
#include<conio.h>
void main( )
Function
Name
main function
Starting point of
program execution
Program
Body
Body End
Get character
function. It get a
character at runtime.
But we use it to stay
screen to see output
String or message to be
displayed on monitor. It must be
enclosed in double quotes( )
>>
cout
<<
Monitor
<<
cerr
Standard output stream
Memory
1.
2.
3.
10
Programming Style
C++ is a free-format language, which means that:
Extra blanks (spaces) or tabs before or after identifiers/operators are ignored.
Blank lines are ignored by the compiler just like comments.
Code can be indented in any way.
There can be more than one statement on a single line.
A single statement can continue over several lines.
In order to improve the readability of your program, use the following conventions:
Start the program with a header that tells what the program does.
Use meaningful variable names.
Document each variable declaration with a comment telling what the variable is
used for.
Place each executable statement on a single line.
A segment of code is a sequence of executable statements that belong
together.
Use blank lines to separate different segments of code.
Document each segment of code with a comment telling what the segment
does.
11
Alphabets from A to Z or a to z
The digits from 0 to 9
Underscore(_) can be used
The first character of an identifier can not be a digit
The name of an identifier can not be a reserve word
No space allowed in the name of identifier
Valid Name:
A
Student_Name
_Fname
Pi
Inalid Name:
$Sum //special ch.
6StName // 1st letter digit
F name // no space allowed
int // reserve word
12
Identifier (variable)
Declaration
Syntax
Data-Type Space Variable-Name(Indentifier);
e.g.
int frstNumber;
char choice;
float divide;
long output;
Identifier (variable)
Initialization
Syntax
Data-Type Space Variable-Name(Indentifier) = Value;
e.g.
int frstNumber=10;
char choice=y;
float divide=0.0;
13
Memory Concepts
cin>>
first;
Assume
user entered 45
Variable
Identifier
first
45
first
45
second
72
first
45
second
72
cin>>second;
Assume
sum
user entered 72
= first + second;
sum
117
14
= (assignment operator)
Assigns value to variable
Binary operator (two operands)
Example:
sum = variable1 + variable2;
15
short
2 bytes
int
long
4 bytes
float
4 bytes
double
8 bytes
long double
10 bytes
Character
char
1 byte
Boolean
bool
1 byte
Floating
point data
16
Description
char
short int (short)
int
Range of Values
AVR GCC
MSVC++
Short integer
Signed: -2,147,483,648 to
2,147,483,647
Unsigned: 0 to 4,294,967,295
Signed: -2,147,483,648 to
2,147,483,647
Unsigned: 0 to 4,294,967,295
Integer
AVR GCC
MSVC++
Long integer
Signed: -2,147,483,648 to
2,147,483,647
Unsigned: 0 to 4,294,967,295
float
1E 38 (7 decimal digits of
precision)
1E 38 (7 decimal digits of
precision)
double
1E 38 (7 decimal digits of
precision)
long double
17
18
Arithmetic
19
Comments
/*
This program is used to show the
square of even numbers from 10 to
100.
*/
20
Tokens
Tokens are individual words and punctuation marks in passage of text.
In C++, program the smallest individual units are known as C Tokens.
C++ has Six types of Tokens. The Tokens are shown in figure. C++
programs are written using these tokens and the syntax of the
language.
21
22
C++ keywords
Each
Thank
You
New
Computer
Scientists
24
Memory Concepts
Variable
names
25