🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Structures and Unions: all 10 questions

Quiz: Structures and Unions · Question 6 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
struct Point { int x; int y; };
int main(void) {
    struct Point a = {1, 2};
    struct Point b = a;
    b.x = 9;
    printf("%d %d\n", a.x, b.x);
    return 0;
}
  1. A.9 9
  2. B.1 9
  3. C.1 1
  4. D.Compile error: structs cannot be assigned
Answer & explanation

Correct answer: 1 9

Assigning a struct copies every member, so b is a separate copy; changing b does not change a.

Can you get the rest right without peeking?

Take the timed Quiz: Structures and Unions quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →