ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
what is the size of this class
class size
{
public:
	char data1;
	double d;
	int data2;
	char data3;
	double data4;
	short data5;
};

please explain the padding for these double variables.
 Question Submitted By :: Tarun
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 1
double will occupies 8 bytes. so here two double data type 
variables create then this class size is 21

char    1 b
double  8 b
int     2 b
char    1 b
double  2 b
short   1 b
 
Is This Answer Correct ?    0 Yes 0 No
Nomesh
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 2
This size is 32

Char : 1 + 3 bytes padding
Doube : 8 Bytes
int   : 4 bytes 
char  : 1 + 3 bytes padding
double : 8 bytes
short : 4 bytes

so 32 bits
 
Is This Answer Correct ?    0 Yes 0 No
Nivvy
 
 
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 3
absolutely correct navvy agreed !!

just a minor change 

short : 2  bytes + 2 byte padding
 
Is This Answer Correct ?    0 Yes 0 No
Abhishek
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 4
22
 
Is This Answer Correct ?    0 Yes 0 No
Lakshmi Sahu
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 5
I have a small doubt.. isnt it based upon the underlying 
platform on which this piece of code is run?
as far as my c++ knowledge goes, the size of each datatype 
varies for each platform unlike java. this is the reason 
why java ensures portability of code, while c++ doesnt.
please tell me if i am wrong...
 
Is This Answer Correct ?    0 Yes 0 No
Kanthi
 
  Re: what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.
Answer
# 6
Just as an extension to my point in the previous post... 
http://www.cplusplus.com/doc/tutorial/variables.html

the section fundamental datatypes in the above article 
substantiates my point...
 
Is This Answer Correct ?    0 Yes 0 No
Kanthi
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
What is the difference between Class and Structure? HP2
why can't we declare data member of class auto register or extern  1
How do you link a C++ program to C functions?  2
Which algorithm do you like the most? Why? Google1
What are the techniques you use for debugging? Adtran1
What is a pure virtual function? Why is it represented as = 0...how is the internal implementation for the same CTS3
How to change constant values? Symphony3
what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.  6
how to swap two numbers with out using temp variable  6
What are the differences between a struct in C and in C++? Wipro4
Do we have private destructors? Symphony9
what is importance of data sturture in a programming language? L&T10
What are the types of STL containers?  1
What is object slicing and how can we prevent it? Tech-Mahindra2
How can you find the nodes with repetetive data in a linked list? Lucent1
What are Virtual Functions? How to implement virtual functions in "C" ?  2
How is an Abstract Base Class(ABC) related to an "Abstract Data Type" (ADT)  2
What are the different operators in C++? HP1
is throwing exception from a constructor not a good practice ? Ericsson4
Write a program that read 2o numbers in and array and output the second largest number. Can anybody help??  2
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com