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

Discussion

What will be the output of the following program?

#include <stdio.h>

int main()
{
static unsigned int a = 23;
register unsigned char c = 'R';
auto long unsigned q = 345L;
static long signed p = 345L;
printf("a = %u c = %c", a ,c);
printf("\nq = %ld p = %ld", q, p);
return 0;
}

 

  • A.a=23 c=R q = 345 p = 345
  • B.A=23 c=R 0 0
  • C.Garbage value
  • D.A=23 c=R q = 345 p = 345

Answer: A

Correct answer: a=23 c=R q = 345 p = 345

Each variable prints its own value, and the storage classes affect only lifetime and placement, not the values: a is 23, and c printed with %c shows the character R. The two long variables both hold 345 and print with %ld as 345. The only real trap is the case of the letters in the options - the format string writes a lower-case a.

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

Post your comment

Please log in or register to post a comment.