Introduction To Object Oriented Programming
Introduction To Object Oriented Programming
Overview of C language
The C character set: it denotes any alphabet, digit or special symbols used to represent information.
Tokens
The smallest unit of the program is called Token. Token is a generalized term which can be further divided into
sub-divisions like keyword, operator, punctuators, identifier, literals (constants, e.g 4).
Identifiers
A single character or a sequence of characters given by the programmer as a name of some program entity is
called as an identifier.
Variable
Variables are the named memory locations whose value can be change during program run. A variable is
declared using the data type in front of the name of the variable, for eg int x;
Constant
Constant are those memory location which do not change their value during a program run unless and until
deliberately changed by the programmer.
Reference
Reference is an alternate name of an already declared variable. It is declared using & sign. For example
int total;
int & sum=total;
this means sum and total are names of same memory location both containing the same value.
Function
Function is a named set of instructions or a named block of code used to perform a specific task. Functions
increase the modularity of a program, and at the same time are reusable.
Function Prototype
A Function Prototype is the declaration of the function that tells the program/compiler about the return type , the
name ,the number and type of arguments. For eg,
int ABC (int , int);
or
int ABC (int x, int y);
here , the int before ABC is the return type which tells that the function returns an integer value. ABC is the
name of the function, and the two int (inside the bracket) tells that the function takes two input of integer type.
It is optional to provide the names of the variables hence a function prototype can be written in two ways as
shown above.
add(x,y)
getch( );
//function call
}
void add(int a, int b)
//function definition
{
int sum;
sum=a+b;
cout<<result is<<sum;
}
In the above program x and y are actual parameters and a and b are formal parameters.
//function protoype
clrscr( );
int x, y;
cout<<enter two integers;
cin>>x>>y;
add(&x, &y) ;
//function call
getch( );
}
void add(int * a, int * b)
//function definition
{
int sum;
sum=a+b;
cout<<result is<<sum;
}
//function protoype
clrscr( );
int x, y,receiver;
cout<<enter two integers;
cin>>x>>y;
receiver=add(x,y);
getch( );
}
int & add(int a, int b)
{
int sum;
int & ref=sum;
sum=a+b;
return ref;
}
//function call
//function definition
Inline Function
Inline functions are those functions whose function call statements are replaced by the function code before
compilation of the program. Whereas in case of normal functions, the function code is loaded into the memory
during the execution of program only after encountering a function call statement. Any program is first
compiled and then executed.
To make a function inline the keyword inline is placed before the return type of the function.
Function Overloading
Two functions having the same name but different signature (list of parameters) is called as function
overloading. At function call, the correct function is invoked depending on the type and number of the
arguments.
Object
An object is any identifiable entity with some characteristic and behavior. In programming an object is an
instance of a class which contains the variables declared in the class to which it belongs.
Class
A class encapsulates (binds together) the characteristic and behavior of an object into one unit and it represents
a group of objects that have common properties. In programming terms a class contains the data (variables) and
the associated function.