Sep 6, 2011

sizeof operator , learning with experiments

sizeof a very interesting operator, lets do some experiments with it to gain more understanding about it.

Lets look at the msdn definition of it first :-
Yields the size of its operand with respect to the size of type char [definition from msdn].

Now lets start experimenting with it :-

what will following statement yields

a) sizeof function ?
        sizeof(&main);
        sizeof(&printf);

b) sizeof an empty class ?
        class A {};
        sizeof(A)

c) Can sizeof return 0 ?

d) What will be the output of following program ?
        int i = 1;
        sizeof(i++);
        cout<<"i="<<i;

e) sizeof following class ?
       class A { char c; int i; };
       sizeof(A)

Now lets look at them one by one

a) sizeof function ?
        sizeof(&main);
        sizeof(&printf);

Answer : sizeof(&main) will return 4 on 32 bit OS.
same hold true for sizeof(&printf). And the reason is very straight forward. As its returning size of function pointer.


b) sizeof an empty class ?
        class A {};
        sizeof(A);
Answer : Its a very interesting question which have very straight forward answer. It directly depends on sizeof operator implementation, if one looks at msdn documentation it says sizeof operator never returns zero. Considering this fact it returns 1.
For more details one can go through link (stroustrup's FAQs):-
                                          http://www2.research.att.com/~bs/bs_faq2.html#sizeof-empty

c) Can sizeof return 0 ?
Answer : NO, sizeof operator never returns 0.


d) What will be the output of following program ?
        int i = 1;
        sizeof(i++);
        cout<<"i="<<i;
Answer : output would be 1, sizeof operator gets resolved at compile time only, no run-time execution will be entertained for sizeof operator. So the output would be 1.


e) sizeof following class ?
        class A { char c; int i; };
        sizeof(A);
Answer : Don't hurry up to reply with 5 byte, because it depends on the byte alignment of class.
If it is 1 byte aligned, output would be 5;
And for 4 byte aligned, output would be 8;




73 comments:

Repairing of Lenovo laptop are very well done by us as we have experts that are well versed with the technology used in Lenovo laptop to build them. Get in touch with us for swift & skilled help in repairing your Lenovo laptop system. Lenovo service center in Delhi. Call us: 7217871051
Lenovo Service Center in Delhi

Repairing of hp laptop are very well done by us as we have experts that are well versed with the technology used in hp laptop to build them. Get in touch with us for swift & skilled help in repairing your hp laptop system. hp service center in Delhi. Call us: 7217871051
Hp Service Center in Delhi

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7217871051
Lenovo Service Center in Ghaziabad

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
Lenovo Service Center in Uttam Nagar

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
HP Service Center in Uttam Nagar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
Lenovo Service Center in Neta ji subhash Place

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
Hp Service Center in Neta ji subhash Place

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Hp Service Center in Sec-14 Gurgaon

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Sec-14 Gurgaon

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Hp Service Center in Palam Vihar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Palam Vihar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Manesar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in M.G. Road

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Ghaziabad

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Hp Service Center in Ghaziabad

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in DLF Garden City

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service Center in Mangolpuri

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service Center in Sohna-Road

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp service center in Borivali

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service Center in Andheri West

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Lenovo Laptop Service Center in Rohini

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp service center in Bandra

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service in Center in Malad

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp service center in Udyog Vihar

Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324.
Lenovo service center in Andheri West

Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324.
Lenovo service center in Borivali

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Hero Honda Chowk

Hp Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Hp Service Center in Malad

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Hp Service in Center in Santacruz

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 7217871051
Hp Service Center in Lajpat-Nagar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service in Center in Janakpuri

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Rohini

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Hp Service Center in Paschim Vihar

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324
Lenovo Service Center in Rajouri Garden

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Lenovo Service Center in Nehru-Place

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Lenovo Service Center in Pitampura

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 9891868324
Hp Service Center in Pitampura

Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 9891868324
Lenovo Service Center in Mangolpuri

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Hp Service in Center in Okhla

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Lenovo Service in Center in Okhla

Lenovo Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Lenovo Service Center in Greater Noida

Hp Laptop Service Center offer fixing for your PC needs, we are experts in PC chip level fix, call us: 9891868324.
Hp Service in Center in Greater Noida



Lenovo Laptop Service Center offer fixing for your PC needs, we are specialists in PC chip level fix, call us: 7042640351.
Lenovo Service Center in Chattarpur


The school keeps up the creators' commitment to significance in all fields, with complement on its saying Higher Stronger Brighter. High morals are a fundamental of a nice person. Contact on us: 8130269997.
cbse school in Rohini

The school keeps up the creators' commitment to significance in all fields, with complement on its saying Higher Stronger Brighter. High morals are a fundamental of a nice person. Contact on us: 8130269997.
Top Schools in Rohini

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Outdoor advertising

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Hoarding advertising

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Digital wall painting

It is attempt of Mast Banarasi Paan Company to construct a chain of establishment outlets in a large portion of the urban areas of India to guarantee that heavenly Banarasi Paan is made accessible to each client with a similar flavor, taste, quality and cleanliness and we are the best paan supplier in INDIA
Paan Café

It is attempt of Mast Banarasi Paan Company to construct a chain of establishment outlets in a large portion of the urban areas of India to guarantee that heavenly Banarasi Paan is made accessible to each client with a similar flavor, taste, quality and cleanliness and we are the best paan supplier in INDIA
Flavour Paan

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838122281.
Hp Service Center in BKC-Mumbai

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838122281.
Dell Service Center in Mumbai

The school maintains the authors' obligation to greatness in all fields, with accentuation on its maxim Higher Stronger Brighter. High ethics are an essential of a decent individual. Contact on us: 8130269997.
GD GOENKA
Top Schools in Rohini
cbse school in Rohini

Hp Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Hp Service Center in Mumbai

Lenovo Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Lenovo Service Center in Mumbai

Dell Laptop Service Center offer repairing for your laptop needs, we are experts in laptop chip level repair, call us: 7838446546.
Dell Service Center in Mumbai

The school maintains the authors' obligation to greatness in all fields, with accentuation on its maxim Higher Stronger Brighter. High ethics are an essential of a decent individual. Contact on us: 8130269997.
Nursery Admissions 2021-2022
Best Schools in Delhi
GD GOENKA Rohini

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Outdoor Advertising Companies in Delhi

Arising as a broadly perceived promoting organization in all features of publicizing and marking arrangements centering in outside, on the web and electronic media spaces. Contact on us: 9868946230.
Hoardings in Delhi

G.D. Goenka Public School Rohini Sector- 9 is a Co-educational Senior Secondary School, recognized and affiliated to the Central Board of Secondary Education (CBSE). It has classes from Preschool till Class 12th. The school upholds the founders' commitment to excellence in all fields, with emphasis on its motto Higher Stronger Brighter. High morals are a prerequisite of a good human being.
top 10 schools in rohini
cbse school in Delhi
Nursery Admissions 2021-2022

Four Square Media Services is engineered in Delhi NCR. The Company eyes the vision of getting one of the India's striking and assumed Outdoor Advertising Companies in Delhi by fulfilling our client's basics and giving our colossal clients the best quality results using our ability and rich experiences of advancing. Contact on us: 9868946230.
Hoardings in Delhi
Digital wall painting
Advertising wall painting

Four Square Media Services is engineered in Delhi NCR. The Company eyes the vision of getting one of the India's striking and assumed Outdoor Advertising Companies in Delhi by fulfilling our client's basics and giving our colossal clients the best quality results using our ability and rich experiences of advancing. Contact on us: 9868946230.
Hoardings in Delhi
Digital wall painting
Wall painting advertising
Outdoor advertising

Four Square Media Services is engineered in Delhi NCR. The Company eyes the vision of getting one of the India's striking and assumed Outdoor Advertising Companies in Delhi by fulfilling our client's basics and giving our colossal clients the best quality results using our ability and rich experiences of advancing. Contact on us: 9868946230.
Digital wall painting
Auto Rickshaw advertising
Advertising wall painting
Auto rickshaw ad in delhi
Rural wall painting advertising

Bs system solution in Delhi provides the best solution for laptop repair. Our experienced engineers take complete care and responsibility for your device and provide you a high-quality solution. The Lenovo Laptop Technical support is available for all range of customers. IF YOU ARE INTERESTED YOU MAY CALL -9891868324, 9643406897, and 9643409808
laptop repairing center in Delhi
best laptop service center in Delhi

Bs system solution in Delhi provides the best solution for laptop repair. Our experienced engineers take complete care and responsibility for your device and provide you a high-quality solution. The Lenovo Laptop Technical support is available for a range of customers. IF YOU ARE INTERESTED YOU MAY CALL -9891868324, 9643406897, and 9643409808.
multi brand laptop repairing in Mumbai
Best laptop repairing center in Mumbai

The ventilated external shell protects against electrical hazards, molten substance splash and squeezes. With its eventuality for integration of a Petzl headlamp, hearing protection, and multiple accessories, it's an entirely modular helmet, therefore meeting the specific fresh conditions of professionals.
petzl HELMETS Vertex price in Mumbai
Petzl HARNESS Avao Bod price in Mumbai

Spotting the best wedding photographer in Kolkata can be quite a hectic task. Here’s Crazy lens photography to end your quest. We specialize in a fun and candid style of wedding photography, which can be customized according to your needs.
best pre wedding photographer in kolkata
pre wedding photography in kolkata

Klever Trade is a new-generation online stock trading platform which will change the way you trade forever. Klever Trade is a new-generation online stock trading platform which will change the way you trade forever. 02614245940
How to trade in algo
Best api for algo trading

Denex International - India's largest manufacturer and exporter of surgical disposables has a wide product base and are regularly adding new medical disposables to the list. The products include I.V. Cannula with PTFE Catheter of different gauges/ sizes, non-woven fabric products such as SURGEON'S GOWNS & APRONS, O.T. SHEETS and are manufactured under the brand name Amie IV Cannula (All Gauges). 9310148912
IV Cannula Manufacturer
IV Catheter Manufacturer

If you are planning to take the CELPIP test and looking forward to achieve your highest score, then there is great chances our course can really help you achieve your desired score in all four modules. In fact more than 85% of our students have achieved their dream score through our live online sessions.
celpip training near me
celpip training center near me

The ventilated external shell protects against electrical hazards, molten substance splash and squeezes. With its eventuality for integration of a Petzl headlamp, hearing protection, and multiple accessories, it's an entirely modular helmet, therefore meeting the specific fresh conditions of professionals.
Petzl ICE AXES Quark price in Mumbai
Petzl CRAMPONS Sarken price in Mumbai
Petzl ROPES AXIS price in Mumbai
Petzl HEADLAMPS Tikina price in Mumbai

Post a Comment