Skip to main content

How copy constructor is different from constructor?

A copy constructor is used to declare and initialized an object from another object. But constructor enables an object to initialize itself when it is created. It is known as automatic initialization of object. So copy constructor is different from constructor.
     For Example:
     #include<iostream.h>
      class copy
  {
        int id;
     public:
      copy()
    {   }
    copy(int a);
      {
         id=a;
     }
        copy(copy & x)
    {
       id=x.id;
      }
   void display(void)
    {
        cout<<id;
    }
   };
void main()
     {
        copy a(300);
        copy b(a);
        copy c=a;
        copy d(b);
          cout<<"\n ID of a:  ";a.display();
          cout<<"\n ID of b:  ";b.display();
          cout<<"\n ID of c:  ";c.display();
          cout<<"\n ID of d:  ";d;display();
    return();
       }

Output of this program is:

ID of a: 300
ID of b: 300
ID of c: 300
ID of d: 300


Comments

Popular posts from this blog

What is manipulator in C++?

Answer: Manipulators are special functions that can be included in the I/O statement to alter the format parameters of a stream. Table-2 shows some important manipulator functions that are frequently used. To access these manipulators, the file < iomanip.h > should be included in program.                               Table-2               Manipulators                                                    Equivalent ios function               set...

Explanation of Graphics in C programming

   The header file graphics.h should be included to use graphics related built in functions. Again, the variable gDriver is an integer variable that specifies graphics driver to be used. Device drivers are small programs which talk directly to the hardware. Graphics drivers are a subset of device drivers and are applicable only in the graphics mode. The initialization of this variable to DETECT is to set another variable gMode to the highest resolution available for the detected driver.  The value of this variable gDriver may be another than DETECT (e.g. 1 for CGA, 9 for VGA.). The variable gMode is an integer that specifies initial graphics mode.       The built in function initgraph() is for graphics initialization. The syntax for this is as   initgraph(&graphics_driver, &graphics_mode, path_to_driver);   path_to_driver specifies the directory path where initgraph() looks for graphics drivers ( .BGI files). Thi...

BIOS

BIOS stands for Basic Input Output System. It is is kind of OS pre- attached in the system Design to detect every I/O devices It holds basic drivers -checks all I/O devices -Loads main OS -Responsible for starting System switched on manufactured by AMI,Phonix,award,Baiostar POST error test, boots trap load, BIOS is unintrusive system. CMOS and BIOS are two different components of the motherboard. CMOS work as storage if BIOS. A basic software program containing all BIOS is permanently stored in the ROM. every essencial holds program Tresh passing without knowinig is called intrusive.