Page 20 - Modular_V2.0_C++_Flikpbook
P. 20
Program 1: To swap the values of two variables using third variable.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, temp;
a = 10;
b = 20;
cout<<"Values of a and b before swapping are "<<a<< " and " <<b<<
".\n";
temp = a;
a = b;
b = temp;
cout<<"Values of a and b after swapping are "<<a<< " and " <<b<<
".\n";
getch();
}
The output of the above program is displayed as follows:
DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, program: TC
Values of a and b before swapping are 10 and 20.
Values of a and b after swapping are 20 and 10.
Constants
A constant is a fixed value which does not change its contents during the program execution. In
C++, constants can be divided as follows:
Integer Constants: An integer constant is a numeric value without any fractions. For example:
10, -45, 35, 56, etc.
Floating-Point Constants: Any real number in which a fraction is denoted by a decimal
symbol. For example: 345.64, -867.22, 0.8763, etc.
String Constants: A string value is a collection of one or more characters written in single or
double quotes. For example: 'A', "Hello", "Welcome to C++", etc.
Delimiters
C++ allows some special characters in its coding called delimiters or punctuators. These are:
{ } ( ) , ; =
Braces { }: These are used to specify the start and end of a block of code like main( ) function.
Parentheses ( ): These are used with function names to enclose parameters.
18
Touchpad MODULAR (Ver. 2.0)

