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

How can I get random integers in a certain range?

813


What are global variables and explain how do you declare them?

805


What is this pointer in c plus plus?

820


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2904


How do you use a 'Local Block'?

950


What is the difference between typedef and #define?

778


What is the difference between class and object in c?

833


What is wrong in this statement?

829


What are the types of i/o functions?

989


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

1744


Explain what is the stack?

856


How do you define a string?

869


What does do in c?

805


Explain continue keyword in c

797


Why we use int main and void main?

811