Page 21 - Modular_V2.0_C++_Flikpbook
P. 21
Comma ( , ): It is used to separate two variable declarations in same line.
Semicolon ( ; ): It is used to terminate a statement in C++.
Equal sign ( = ): It is used to assign a value to a variable.
Operators
Operator
Operators are special symbols in C++ that are used to perform
calculations. They are used along with operands or values to get the
desired result. For example: 5 + 3
In the preceding example, 5 and 3 are the operands and + (plus) is an
operator. The plus operator is used to perform the addition operation.
Other operators are - (minus), * (multiply) and / (divide). We will learn
Operands
more about operators in the next chapter.
Program 2: To calculate the sum of two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, sum;
DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, program: TC
a = 10; The sum of two numbers is:30_
b = 20;
sum = a + b;
cout<<"The sum of two numbers is:"<<sum;
getch();
}
MORE SOLVED PROGRAMS
Program 3: To swap the values of two variables without using third variable.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
a = 15;
b = 25;
cout<< "Values of a and b before swapping are " << a << " and " <<
b << ".\n";
19
Getting Started with C++

