Posts

Data Structure

Image
A data structure is a specialized format for organizing and storing data.  Classification of data structure: Primitive Data Structure: Data structures that are directly operated upon by machine-level instructions are known as primitive data structure. Examples -  Integer, Floating point, Character, Double, Pointer. Operations on Primitive Data Structure: Create : Create operation is used to create a new data structure. This operation reserves memory space for the program element. This operation is normally performed with the help of a declaration statement. Example: int x; Select: This operation is used to access data within a data structure. Example: cin >> x; Update: This operation is used to change or modify the data in a data structure. An assignment operation is a good example for an update operation. Example: x = 5; Destroy: this operation is used to destroy or remove the data structure from the memory space. Delete operator is used to perform this...

Memory allocation of pointers

  Memory allocation of pointers: Memory allocation is done in two ways 1.     Static memory allocation 2.     Dynamic memory allocation Static memory allocation: ·        The amount of memory to be allocated is pre known. ·        The memory is allocated during compilation time. ·        Ex: int a; // allocates 2 bytes. ·        Variable remains permanently allocated. Dynamic memory allocation: ·        Memory is allocated during the execution of the program. ·        C++ supports dynamic allocation and de allocation of objects using the new and delete operations. new operator: ·        We can allocate storage for a variable while program is running by using new operator. ·        Ex: ...

Pointers

  Pointer is a variable that holds a memory address of another variable. Pointer declaration: Syntax:   Dataype *variable_name; Data_type – any valid data type supported by C++. variable_name – name of pointer variable. * indicates that it is a pointer variable Pointer Initialization: ptr=&num; The ‘&’ is the address operator, and it represents the address of the variable. In the above statement ptr is a pointer variable, num is a normal variable. The address of num variable is stored in pointer variable ptr. #include<iostream.> void main( ) {           int num,*p;           num=5;           p=&num;           cout<<”value of num”<<num<<”\naddress of num=”<<p; } Pointer operator or Indirection operator: The ...

Problem 3: Find the result

  Find the Output of the following code: for ( i = 1 , j = 1 ; i <= 5 , j <= 2 ; i ++ , j ++ ) {      cout << “ i = “ << i ;      cout << “  j = “ << j ;      cout<<endl; } please enter the Output in the comment section

Problem 2: Find the result

  Find the Output of the following code: for ( i = 1 , j = 1 ; i <= 3 ; i ++ , j ++ ) {      cout << “ i = “ << i ;      cout << “  j = “ << j ;      cout<<endl; } please enter the Output in the comment section

Solve this Code: Problem 1

Find the Output of the following code: for ( i = 1 , j = 1 ; i <= 3 ; i ++ ) {      cout << “ i = “ << i ;      cout << “   j = “ << j ;      cout<<endl; } please enter the Output in the comment section

Inheritance Part 3, Virtual Base Class

Image
Virtual Base Class: When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base class is known as virtual base class. This can be achieved by proceeding the base class name with virtual. Ex: class a {             ---             --- }; class b: virtual public a {             ----             ---- }; class c:virtual public a {             ----             ---- }; class d:public b,public c {         ...