You are on page 1of 4

Delhi Public School, R.K.

Puram Computer Science

HeaderFile Functions, Objects Member Functions


iostream.h Objects: cin,cout
Member functions:read(),write(),getline(),get(),put()
fstream.h Member functions:
open(),close(),read(),write(),getline(),get(),put(),eof()
stdio.h gets(),puts()
stdlib.h randomize(),random()
iomanip.h setw()
string.h strlen(),strcpy(),strcat(),strcmp(),strcmpi()
ctype.h isupper(),islower(),isalnum(),isdigit(),isalpha(),
toupper(), tolower()
math.h sin(),cos(),exp(),frexp(),log(),abs(),fabs(),sqrt(),pow()
conio.h clrscr(),getch(),gotoxy()

Importance of main()
main() function is the first function to be executed in the program.
All the remaining functions in the program are either called from main() or from the
functions, which are called by main() function.

Preprocessor Directives #include and #define


The preprocessor is used to handle directives for source file inclusion (#include)
or defining macro definitions (#define).

#define
It is used to define a macro. The macro substitution is done during compile time.
For example:
#define Area(L,B) L*B
void main()
{
int l,b,ar;
cin>>l>>b;
ar=Area(l,b);
cout<<ar<<endl;
}

Run-time error
A run-time error occurs during the execution of the program, when the program
performs an illegal/unexpected operation.
For example:
int a,b,c;
cin>>a>>b;
c=a/b;//will result in Run-time error if b entered as 0

Syntax Error
A syntax error occurs when the compiler is unable to translate the program to machine
language due to violation of rules of the programming language.
For example: (In C++, condition in a if statement not enclosed in brackets)
if X>90
cout<<X<<endl;

C++ Quick Review By Mukesh Kumar 1/4


Delhi Public School, R.K.Puram Computer Science

Logical Error
A logical error occurs when the program contains wrong formula or wrong calculation,
which may be syntactically correct. The program having logical errors may give some
output but not the expected one.
For example:
//The formula used for calculating average
//of five subjects marks as
Ave= Eng+Math+Phy+Chem+Comp/5;

Actual Parameter
A parameter that is used in the function call to send the actual values to the function
is known as actual parameter.

Formal Parameter
A parameter that is used in the function definition to receive the values from actual
parameter is known as formal parameter.
For example:
void Square(int A)//A is formal parameter
{
cout<<2*A<<endl;
}
void main()
{
int N=4;
Square(N);//N is actual parameter
}

Call by Value
In call by value, actual parameter and formal parameter have different memory
locations, so the changes done in the formal parameter are not reflected back in the
actual parameter.

Call By reference
In call by reference, actual parameter and formal parameter share the same memory
location, so the changes done in the formal parameter are reflected back in the actual
parameter. Requires & sign in formal parameter.
For example:
void Calc(float Sal,float &Itax)
{ //Sal Call by value, Itax Call by reference
Sal=1.1*Sal;
Itax=0.3*Sal;
}

Default Parameter
It is used to provide a default value to a parameter. If no value is sent from the actual
parameter, the formal parameter automatically gets this default value.
For example:
void PrintLine(int N=20)
{
for (int C=0;C<N;C++) cout<<-;
}

C++ Quick Review By Mukesh Kumar 2/4


Delhi Public School, R.K.Puram Computer Science

void main()
{
PrintLine(40);
PrintLine();
}

Function Prototype
A function prototype in C++ is a declaration of a function that does not require the
function body but does specify the function's name, parameter types and return type.
While a function definition specifies what a function does, a function prototype can be
thought of as specifying its interface. In the function prototype, argument names are
optional, however, the type is necessary alongwith & or [] (if required).
Foe example:
void Disp(char []);
void main()
{
Disp(Hello);
}
void Disp(char Msg[])
{
cout<<Msg<<endl;
}

Global Variable
A variable, which is declared outside all the functions in the program, is known as
global variable. A global variable can be accessed and modified in any part of the
program (i.e. in any function). If local variable carries identical name as global
variable, to access the global variable scope resolution operator (::) is required.

Local Variable
A variable, which is declared inside a function or a compound statement in the
program, is known as local variable. A local variable can be accessed and modified in
the function or the compound statement in which it is declared.
For example:
int Num1=100,Num2=200;//Global Variables
void main()
{
int Num2=20,Num3=30;//Local Variables
Num1+=10;Num2+=20;::Num2+=30;Num3+=40;
cout<<Num1<<Num2<<::Num2<<Num3<<endl;//1104230240
}

Type Casting
It is an explicit process of type conversion from a data type to another.
For example:
int A=1,B=2;
float C=(float)A/B;
OR
int P=65;
cout<<(char)P<<endl; //Type Casting

C++ Quick Review By Mukesh Kumar 3/4


Delhi Public School, R.K.Puram Computer Science

(Automatic) Type Conversion


It is an implicit process of type conversion from a data type to another.
For example:
int P=65;
char CH;
CH=P;//Type Conversion
cout<<CH<<endl;

Ternary Operator/Conditional Operator


It is an operator (?) with three operands.
For example:
int A=10,B=20,C;
C=(A>B)?A:B;
OR
int A=10,B=20;
(A>B)?cout<<A:cout<<B;

Use of typedef
typedef is a keyword in C++. It is used to provide an alternative name to existing data
types.
For example:
typedef char STR[80];
void main()
{
STR S;//will mean same as char S[80];

Insertion and extraction operators


<< is known as insertion operator in C++ and is used with cout.
>> is known as extraction operator in C++ and is used with cin.

Type modifiers
Type modifiers are used to modify range and/or size of the data type.
short, long, unsigned, signed are type modifiers in C++

Access Modifier
const is an access modifier in C++. It is used to declare an identifier, whose value will
remain same throughout the program.
For example:
const int MAX=90;

C++ Quick Review By Mukesh Kumar 4/4

You might also like