typedef struct
{
int i:8;
char c:9;
float f:20;
}st_temp;

int getdata(st_temp *stptr)
{
stptr->i = 99;
return stptr->i;

}


main()
{

st_temp local;
int i;
local.c = 'v';
local.i = 9;
local.f = 23.65;
printf(" %d %c %f",local.i,local.c,local.f);
i = getdata(&local);
printf("\n %d",i);
getch();

}
why there there is an error during compiling the above
program?



typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { ..

Answer / vadivelt

1.Maximum no of bits to a bitfield variable, allocated by any
compiler is = sizeof(datatype of variable) * 8;
and minimum of 1 bit.

2.Almost all the compilers allocates 1 byte for character
datatype(not mandatory. ie., memory allocation purely
compiler dependent).

So the error found here is,

In the stucture given, For character variable 'c', you are
trying to allocate 9 bit of memory. But the variable can
hold maximum of 8 bits.
Hence error.

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Interview Questions

WRITE A PROGRAM TO FIND A REVERSE OF TWO NO

7 Answers  


what is the similarities between. system call and library function?

1 Answers   Wipro,


main() { int i=0; while(+(+i--)!=0) i-=i++; printf(i); }

3 Answers  


what are the advantages of a macro over a function?

0 Answers   TCS,


What is the use of structure padding in c?

0 Answers  






please give me answer with details #include<stdio.h> main() { int i=1; i=(++i)*(++i)*(++i); printf("%d",i); getch(); }

3 Answers  


What are local static variables? How can you use them?

0 Answers  


int a[3][5]={ {1,2,3,4,5],{2,3,4,5,6},{10,11,12,13,14}}; int *p=&a; printf(ā€œ%dā€,*(*(x+1)+3));

2 Answers   Wipro,


consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is

4 Answers   TCS,


Write code for initializing one dimentional and two dimentional array in a C Program?

5 Answers   Deshaw, Edutech, GMD,


read a number & print all its devisors using c-program?

3 Answers  


wat is the difference between a definition and declaration? float y;---it looks like a declaration..but it s a definition.how?someone explain

3 Answers   TCS,


Categories