Sie sind auf Seite 1von 4

My Notes C++

Introduction to C++:
High level languages like COBOL, FORTRAN and C known as Procedure
Oriented Programming (POP).
In POP problem is viewed as sequence of things to be done.
Data change may occurs during each function call so debugging is
difficult.
OOP treats data as a critical element and does not allow it to flow freely
through the program.
Programs are divided into objects and each object contains its own data
and function.
Data of one object cannot be changed by function of another object
however it can access the function of another object (Communication of
Objects through function).
Class is the collection of objects of similar types (similar to data structures
in C). E.g. fruit mango fruit=>class and mango=>object.
Wrapping of data and function into single unit (class) is encapsulation.
Inheritance is the process by which object of one class acquire the
properties of objects of another class.
Polymorphism=>Ability to take more than one form. Operator
Overloading.
Namespace defines the scope for the identifiers that are used in the
program.
If inside the main we declare student Asad then student is class and Asad
is object.
Functions which operate on the data of any class is known as member
function.

Structure of C++ Program:


1.
2.
3.
4.

Include Files
Class Declarations
Member functions definition
Main Function Program

Data Types:

My Notes C++

Use of void=>
void *gp;
Here gp becomes generic pointer.
In C char constants are stored as ints therefore sizeof(x)=sizeof(int) in C
but in C++ sizeof(x)=sizeof(char).
Initialization of variables during run time is known as Dynamic
initialization. It is allowed in C++.

Reference Variables:
It provides Alias (Alternative name). One location two Names.
Data_type & reference_name = variable_name e.g. float & sum = total;
Data change occur for both at the same time.
& is no more address operator. Here float & is reference to float.
Application is passing arguments to a function. Void func(int &x) such
function calls are known as Call by Reference.
References can be created for built in data types as well as user defined
data types such as structures and classes.

Operators in C++:
<<

Insertion Operator

>>

Extraction Operator

::

Scope Resolution Operator

: :*

Pointer to Member Declaration

->*

Pointer to Member Operator

.*

Pointer to Member Operator

Delete

Memory Release Operator

End1 Line Feed Operator


New

Memory Allocation Operator

My Notes C++
Setw Field Width Operator

Scope Resolution Operator:


C++ is block structured language. Variables declared with the same name
in different block has different meaning. Block is one pair of curly bracket.
Variables declared inside a block is known as Local Variable.
To access the global variables inside a block, use scope resolution
operator. Syntax : : Variable_Name. e.g. : :var refers to global var and not
local var.

Memory Management Operators:


Pointer_variale = new data_type(Initializing_value); e.g. int *p=new
int(25);
Pointer_variale = new data_type [array_size];
Delete Pionter_variable; e.g delete p;
Delete [size] Pointer_variable; also delete [ ] p is legal for recent
versions.

Manipulators:

Used to format the data display.


Endl and setw.
Endl is equivalent to \n in C (end of the line for display).
Setw is used to put the numbers in right justified.
1234
14

Syntax cout<<setw(width)<<variable_name<<endl;

Relational Expressions yields results of type Boolean such as true or false.


Logical Expression combine two or more relational expression and produce
Boolean type results e.g. a>b && x==10.
x<<3 shift 3 bit position to left. Equivalent to multiplication and division
by powers of 2. Applicable to all types.

Operator Precedence:

My Notes C++

Operators are in order of decreasing precedence.

Functions in C++:
Main () in C have no return type but for C++ it returns int to the operating
system.
At the time of declaration, only function type is necessary because
compiler only checks types and not variables (also called dummy variable)
thus float average (float) is legal.

Inline Functions:
Function take lots of time for calling thats why use of Inline function
happens.
It simply expand in the line where it is invoked.
Syntax
Inline function_header
{

inline double cube ( double a )


{

Function body
}

return ( a*a*a );
}

If the functions are of bigger length then it is better to use normal function
than inline.
DEFAULT ARGUMENTS are the arguments which take the default value
when that value is missing at the time of function call. Add default value
from right to left and not in the middle

Das könnte Ihnen auch gefallen