Professional Documents
Culture Documents
Chapter One
Structures and Pointers
Structures-is an example of derived data type. It is an organized collection of logically related fields that are
referenced by a common name.
syntax:
struct structure_tag
{data_type variable1;
…………………}structure_variable;
struct date
{ int day;
int month;
int year;
}dob;
The dot operator (.)connects a structure variable with a structure element.
syntax: structure_variable.element_name;
Nested Structure- One structure contains another structure.
Array Vs Structure
SlNo Array Structure
1 Derived data type User defined data type
2 Collection of same type of data Different types of data
3 Elements are referenced with subscripts Referenced by using dot operator
4 one array contains another array is One structure contains another structure is nested
multidimensional array structure
5 Array of structure is possible Structure can contain arrays as elements
Pointers:-A variable which holds the address of another variable. Pointer concept was introduced by Harold
Lawson.
Declaration: datatype *variable;
Address of operator(&)-to get the address of a variable.
Value at operator(indirection) (dereference)(*)-retrieves the value at a particular location.
Static Memory allocation- Memory allocation which can be done at compilation time.
Dynamic memory allocation-Memory allocation which can be done at run time.
1. new- creates dynamic memory space
syntax1 : pointer_variable=new datatype;
syntax2: pointer_variable=new datatype(value);
delete pointer_variable; - deletes the dynamic memory space.
Memory leak: If the dynamically allocated unwanted memory is not de allocated by using the delete operator ,a
wastage of memory is occurred. This situation is memory leak.
Pointers can be incremented or decremented. Among the six relational operators , only equality(==) and non
equality(!=) are used with pointers.
Dynamic Array: Array which is created at run time by using “new” operator.
pointer_variable=new datatype[size];
Structure pointer and an element is connected using arrow operator(->)
Self referential structure: A structure in which one of the element is a pointer to the same structure.
Chapter Two
Concepts of Object Oriented Programming
Programming Paradigm: the way in which program is organized. C++ is a multiple paradigm language. It supports
both procedural paradigm as well as object oriented paradigm.
Limitations of POP:
1.Data is under valued
2.Adding new data element may require modifications to all/many functions.
3.Creating new data types(Extensibility) is difficult.
4. Provides poor real world modeling.