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

What is the importance of c in your views?

0 Answers  


what is the difference between unix os and linux os

4 Answers  


HOW CAN ADD OUR FUNCTION IN LIBRARY.

5 Answers  


Hierarchy decides which operator a) is most important b) is used first c) is fastest d) operates on largest numbers

1 Answers  


main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } what is the output?

10 Answers   Ramco,


Do you know the difference between malloc() and calloc() function?

0 Answers  


Write a c pgm for leap year

11 Answers   College School Exams Tests, IBM, TCS,


What are the functions to open and close the file in c language?

0 Answers  


biggest of two no's with out using if condition statement

8 Answers  


What is d'n in c?

0 Answers  


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

0 Answers   GrapeCity,


What is the hardest programming language?

0 Answers  


Categories