Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

#include <stdio.h>
struct st
{
    int x;
    static int y;
};
 
int main()
{
    printf("%d", sizeof(struct st));
    return 0;
}

 

  • A.4
  • B.8
  • C.Compiler Error
  • D.Runtime Error

Answer: C

Correct answer: Compiler Error

There is no static member in C - that is a C++ feature. A structure in C is a layout of data, with no storage shared across instances, so the declaration is rejected. (In C++ it would compile, and sizeof would be 4, since a static member is not part of each object.)

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.