Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

UNIT I

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.

Procedural Vs Object Oriented Programming


In Procedural Programming, the focus is on the procedure and the algorithm involved for doing the desired task.
In Object oriented Programming, the desired task is viewed in terms of the object involved rather than the
procedure for doing it, which means, the data to be manipulated becomes more important. The characteristics
and the behavior of the object involved is identified and bundled as a class.

Characteristics/ Features of Object oriented Programming (OOP)


Fundamentally, there are four features of OOP described as follows:
1. Encapsulation:
The wrapping up of data and functions together into a single unit called class is known as
encapsulation.
2. Data Abstraction:
Abstraction refers to the act of representing the essential features and hiding the implementation details.
3. Inheritance:
The capability of a class to acquire the properties of other class is called inheritance.
4. Polymorphism
Polymorphism means Many Forms. It is the ability to process a data in more than one form. The same
operation is performed differently depending on the type of input data.

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.

Program for Call by Value


Whenever we use a function to do the expected work it is known as function call.The values used for calling
the function are called as actual parameters and the variables used in the function definition are called as
formal parameters. In Call by Value, the value of the actual parameter is passed to the formal parameter.
(Note: In the below program // is used for comment and explanation it is not a part of the program instruction.)
#include<iostream.h>
#include<conio.h>
void add(int, int);
//function protoype
void main( )
{
clrscr( );
int x, y;
cout<<enter two integers;
cin>>x>>y;

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.

Program for Call by Reference(c++)


In Call by Reference, the formal parameters become references to the actual parameters.
#include<iostream.h>
#include<conio.h>
void add(int &, int &);
//function protoype
void main( )
{
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;
}

Program for Call by Reference


In Call by pointer, the formal parameters become pointers to the actual parameters. So the address of the actual
parameters is passed to the formal parameters.
#include<iostream.h>
#include<conio.h>
void add(int *, int *);
void main( )
{

//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;
}

Program for Function Returning Value


Any function with a return statement, should have a receiver(of same data type) to receive the value at the
time of function call.
#include<iostream.h>
#include<conio.h>
int add(int , int );
//function protoype
void main( )
{
clrscr( );
int x, y, receiver;
cout<<enter two integers;
cin>>x>>y;
receiver=add(x,y);
//function call
getch( );
}
int add(int a, int b)
//function definition
{
int sum;
sum=a+b;
return sum;
}

Program for Function Returning Reference


#include<iostream.h>
#include<conio.h>
int & add(int , int );
void main( )
{

//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

Program for Function Returning Pointer


#include<iostream.h>
#include<conio.h>
int * add(int , int );
//function protoype
void main( )
{
clrscr( );
int x, y;
int * receiver;
cout<<enter two integers;
cin>>x>>y;
receiver=add(x,y);
//function call
cout<<*receiver;
getch( );
}
int * add(int a, int b)
//function definition
{
int sum;
int * ptr=& sum;
sum=a+b;
return ptr;
}

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.

You might also like