Posts

Showing posts from May, 2021

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 {         ...

Inheritance Part 2: Types of Inheritance

Image
  Types of inheritance: Types of inheritance are 1.     Single Inheritance If a class derived from a single base class, it is called as single Inheritance. Ex: #include<iostream.h> #include<conio.h> class student {      private:                  int regno;                  cha name[20];      public:                  viod getdata()                  {                              cin>>regno>>name;    ...

Inheritance Part 1

  Inheritance is the Capability of one class to inherit properties from another class. Base class is a class whose properties are inherited by another class. It is also called as super class. Derived Class is a class that inherits properties from base class. It is also called as sub class. An abstract class is one that is not used to create objects and that act as a base class. Advantages of inheritance: ·        Code reusability ·        Testing and debugging is easy ·        Coding is easy because similar type of codes and logics are used in inherited classes ·        Objects can be represented in different levels. i.e. hierarchical arrangement of objects ·        Efficient memory utilization ·        Faster development of codes and easy to extend ·      ...