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

Discussion

What will be the output of the following program?

#include <stdio.h>

static int y = 1;
int main()
{
static int z;
printf("%d %d", y, z);
return 0;
}

 

  • A.Garbage value
  • B.0 0
  • C.1 0
  • D.1 1

Answer: C

Correct answer: 1 0

y is a file-scope static int explicitly initialised to 1. z is a static local with no initialiser, and every object with static storage duration is zero-initialised - unlike an auto variable, which would hold junk. So the output is 1 0.

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

Post your comment

Please log in or register to post a comment.