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


Please Help Members By Posting Answers For Below Questions

What is dynamic dispatch in c++?

1142


What are pointers? What are different types of pointers?

1276


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2836


What is pointer to pointer in c with example?

1206


What is the general form of a C program?

1107


Differentiate between null and void pointers.

1270


How do you convert strings to numbers in C?

1351


What is variable initialization and why is it important?

1404


hi send me sample aptitude papers of cts?

2259


Explain the difference between null pointer and void pointer.

1165


i have a written test for microland please give me test pattern

2816


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

2270


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

1947


In C programming, how do you insert quote characters (‘ and “) into the output screen?

1625


write a c program to find the sum of five entered numbers using an array named number

2270