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 a header file?
What are qualifiers?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
How many bytes are occupied by near, far and huge pointers (dos)?
What is the difference between array and structure in c?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
Explain what is page thrashing?
How can you determine the maximum value that a numeric variable can hold?
Can we change the value of constant variable in c?
Why is it important to memset a variable, immediately after allocating memory to it ?
Explain is it better to bitshift a value than to multiply by 2?
What is the default value of local and global variables in c?
How many loops are there in c?
Can we use any name in place of argv and argc as command line arguments?
What is a struct c#?