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
How do I get an accurate error status return from system on ms-dos?
GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)
What are the key features in c programming language?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
What is volatile variable how do you declare it?
What is the difference between break and continue?
Can static variables be declared in a header file?
What is the use of a static variable in c?
Explain about the constants which help in debugging?
What does #pragma once mean?
What are the complete rules for header file searching?
Write a program to print numbers from 1 to 100 without using loop in c?
Why do we write return 0 in c?
Explain how can I convert a number to a string?
What are the ways to a null pointer can use in c programming language?