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
Tell me can the size of an array be declared at runtime?
Do you know the difference between exit() and _exit() function in c?
Explain do array subscripts always start with zero?
what will be the output for the following main() { printf("hi" "hello"); }
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
How variables are declared in c?
Explain how can type-insensitive macros be created?
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
What are the 4 data types?
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
What are disadvantages of C language.
Why is it usually a bad idea to use gets()? Suggest a workaround.
What are the different types of linkage exist in c?