Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

What is the right type to use for boolean values in c? Is there a standard type?

0 Answers  


void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?

1 Answers  


how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk.

3 Answers   Google,


Program to find larger of the two numbers without using if-else,while,for,switch

11 Answers   iNautix, Wipro,


write a program in c to print **** * * * * ****

1 Answers   TCS,


Can you please explain the difference between malloc() and calloc() function?

0 Answers  


What is header file definition?

0 Answers  


What is identifiers in c with examples?

0 Answers  


Explain zero based addressing.

0 Answers  


What is a list in c?

0 Answers  


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

0 Answers  


Write a program for finding factorial of a number.

0 Answers   Tech Mahindra,


Categories