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


Please Help Members By Posting Answers For Below Questions

What is the difference between union and structure in c?

780


Can a variable be both static and volatile in c?

804


Write a Program to accept different goods with the number, price and date of purchase and display them

5865


What is preprocessor with example?

784


What is difference between far and near pointers?

792


What is #error and use of it?

918


what is a function method?give example?

2121


What is an arrays?

834


write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.

1754


What is the difference between functions getch() and getche()?

828


What is the newline escape sequence?

831


What is c mainly used for?

819


What is pass by value in c?

788


Does sprintf put null character?

788


Why does not c have an exponentiation operator?

810