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 right type to use for boolean values in c? Is there a standard type?
void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?
how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk.
Program to find larger of the two numbers without using if-else,while,for,switch
write a program in c to print **** * * * * ****
Can you please explain the difference between malloc() and calloc() function?
What is header file definition?
What is identifiers in c with examples?
Explain zero based addressing.
What is a list in c?
How can I invoke another program or command and trap its output?
Write a program for finding factorial of a number.