adspace
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 Posted / 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 View All Answers
What is dynamic dispatch in c++?
What are pointers? What are different types of pointers?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
What is pointer to pointer in c with example?
What is the general form of a C program?
Differentiate between null and void pointers.
How do you convert strings to numbers in C?
What is variable initialization and why is it important?
hi send me sample aptitude papers of cts?
Explain the difference between null pointer and void pointer.
i have a written test for microland please give me test pattern
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
In C programming, how do you insert quote characters (‘ and “) into the output screen?
write a c program to find the sum of five entered numbers using an array named number