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?



typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { ..

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

Post New Answer

More C Interview Questions

If the size of int data type is two bytes, what is the range of signed int data type?

0 Answers  


How can I invoke another program or command and trap its output?

0 Answers  


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

0 Answers  


What is the diffences between Windows XP and Windows Visa

1 Answers   Aricent, FHF,


How can I generate floating-point random numbers?

0 Answers  






Explain how do I determine whether a character is numeric, alphabetic, and so on?

0 Answers  


read a number & print all its devisors using c-program?

3 Answers  


while initialization of array why we use a[][2] why not a[2][]...?

0 Answers   Aptech,


stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

0 Answers  


How can I read and write comma-delimited text?

0 Answers  


What is use of integral promotions in c?

0 Answers  


What is the explanation for the dangling pointer in c?

0 Answers  


Categories