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

Discussion

What is the output of this program?

#include <stdio.h>         
struct student
{
  char *c;
};
void main()
{
  struct student s[2];
  printf("%d", sizeof(s));
}

 

  • A.2
  • B.4
  • C.16
  • D.8

Answer: D

Correct answer: 8

s is an array of two structures, each containing a single pointer. On a machine with 4-byte pointers that is \(2 \times 4 = 8\) bytes. Note that sizeof reports the size of the array itself, not the length of anything the pointers reach.

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

Post your comment

Please log in or register to post a comment.