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?
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 |
What is the equivalent code of the following statement in WHILE LOOP format?
Explain what is the advantage of a random access file?
What is the difference between array and pointer in c?
write a progam to display the factors of a given number and disply how many prime numbers are there?
what is pointer ?
10 Answers Kernex Micro Systems,
What is that continue statement??
What is a static variable in c?
AMMONG THE 4 STROAGE CLASSES IN C, WHICH ONE FASTEST?
I heard that you have to include stdio.h before calling printf. Why?
What should malloc() do?
How do you initialize pointer variables?
Is c is a high level language?