retagged by
2,036 views
4 votes
4 votes

Assume that size of an integer is $32$ bit. What is the output of following ANSI C program? 

#include<stdio.h> 
struct st 
{ 
int x; 
static int y;
};
int main()
{
printf(%d",sizeof(struct st));
return 0;
}
  1. $4$
  2. $8$
  3. Compiler Error
  4. Runtime Error
retagged by

1 Answer

1 votes
1 votes

Static variable isn't allowed in struct because C requires the whole structure elements to be placed "together".

So C is correct.

Ref: https://stackoverflow.com/questions/11858678/are-members-of-a-structure-allowed-to-be-static

Answer:

Related questions

2 votes
2 votes
2 answers
1
admin asked Mar 30, 2020
1,033 views
Output of following program#include<stdio.h int main() { int i=5; printf("%d %d %d", i++,i++,i++); return 0; }$7\:6\:5$$5\:6\:7$$7\:7\:7$Compiler Dependent
3 votes
3 votes
1 answer
2
admin asked Mar 30, 2020
1,723 views
Output of following program? #include<stdio.h void dynamic(int s,...) { printf("%d",s); } int main() { dynamic(2,4,6,8); dynamic(3,6,9); return 0; }$2\:3$Compiler Error$4...
3 votes
3 votes
2 answers
3
admin asked Mar 30, 2020
1,508 views
Output of the following program?#include<stdio.h struct st { int x; struct st next; }; int main() { struct st temp; temp.x=10; temp.next=temp; printf("%d",temp.next,x); r...