Thursday, December 20, 2012

Program to show static variable not goes in the memory of object

#include <iostream>
using namespace std;

class laptop
{
    int first_int;           //size of int is 4 byte
    int second_int;       // Means size of this class is 8 Byte
};

class car
{
    static int first_int;
            int second_int;
};

int main()
{
    laptop dell;
    car santro;
   
    cout << sizeof(dell) << endl;
    cout << sizeof(santro) << endl;
}


OUTPUT:
8


This Program show static variable not goes in the memory of object static variable is the only belonging of class.

No comments:

Post a Comment