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

Discussion

What is the output of this program?

#include <stdio.h>
struct test {
    int x = 0;
    char y = 'A';
};
int main()
{
    struct test t;
    printf("%d, %c", s.x, s.y);
    return 0;
}

 

  • A.Error
  • B.garbage value garbage value
  • C.None of these

Answer: A

Correct answer: Error

Two faults, either fatal. C structures cannot have member initialisers - the declaration describes a type, not an object - and the printf refers to s.x and s.y when the variable declared is t.

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

Post your comment

Please log in or register to post a comment.