DIR Return Create A Forum - Home
---------------------------------------------------------
techsuns
HTML https://techsuns.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: OutPut of a Program
*****************************************************
#Post#: 31--------------------------------------------------
Size............
By: vsr Date: August 17, 2012, 3:28 am
---------------------------------------------------------
What will be the size of following structure,justify?
struct employee
{
int emp_id;
int name_len;
char name[0];
};
#Post#: 32--------------------------------------------------
Re: Size............
By: kranthipls Date: August 17, 2012, 10:26 am
---------------------------------------------------------
The size will be 8. That is because in the structure you gave it
as char name[0]. That means you are asking the compiler to
allocate an array with no elements in it. So no memory will be
allocated for it. I hope I am correct.
#Post#: 49--------------------------------------------------
Re: Size............
By: srini Date: August 23, 2012, 3:08 am
---------------------------------------------------------
yes..it is correct :o :o
#Post#: 50--------------------------------------------------
Re: Size............
By: kranthipls Date: August 23, 2012, 4:49 am
---------------------------------------------------------
Let us continue the question:
What will be the size of the structure
struct employee
{
int emp_id;
int name_len;
char name;
};
#Post#: 61--------------------------------------------------
Re: Size............
By: kpr29 Date: August 25, 2012, 5:38 am
---------------------------------------------------------
@Kranthi: 9.
#Post#: 62--------------------------------------------------
Re: Size............
By: kranthipls Date: August 26, 2012, 12:22 am
---------------------------------------------------------
I thought you wil run it check it. Just run it and check it and
you will be amazed to see the answer :o. After seeing the answer
you please come back.
#Post#: 67--------------------------------------------------
Re: Size............
By: nagendra Date: August 29, 2012, 3:24 am
---------------------------------------------------------
@kranthi : i guess the answer is 12, but what is the reason ?
#Post#: 125--------------------------------------------------
Re: Size............
By: kpr29 Date: November 19, 2012, 12:10 am
---------------------------------------------------------
@Kranthi: Nagi is right............. But y 12............ 4+ 4
for int .............. even char it is taking 4 bytes...........
I read about it in web........... Structure does something
called for struture padding........... Which is used for
allignment of different data members in the memory......... 4 +
4 + 4
#Post#: 128--------------------------------------------------
Re: Size............
By: kranthipls Date: November 19, 2012, 12:16 am
---------------------------------------------------------
Exactly
#Post#: 208--------------------------------------------------
Re: Size............
By: dinesh Date: November 26, 2012, 10:11 am
---------------------------------------------------------
It is a technique known as struct hack - used for...
Refer
HTML http://www.geeksforgeeks.org/archives/22677
*****************************************************
DIR Next Page