struct ptr
{
int a;
char b;
int *p;
}abc;
what is d sizeof structure without using "sizeof" operator??
Answer Posted / pradeep
In Linux, its 12 bytes.
int a ------- 4 bytes
char b ------- 1 byte.
but as the next element is integer, it wont fit in the
remaining 3 bytes left after the "char b" occupies the first byte of the 4 byte chunk. so these 3 bytes wont be used for storing "int *p". these will be padded. next 4 bytes will be used for storing *p.
to prove it.
int size;
size = (&(abc.p) + sizeof(abc.p)) - &abc.a ;
printf("size = %d",size);
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Explain what is the purpose of "extern" keyword in a function declaration?
code for quick sort?
What is the use of structure padding in c?
What is string constants?
What is a keyword?
How can I get random integers in a certain range?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
When do we get logical errors?
What is double pointer in c?
What are two dimensional arrays alternatively called as?
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }
What is the use of ?: Operator?
Explain what is the benefit of using #define to declare a constant?
write a program to copy the string using switch case?