Quiz C : Structs & typedef

Structs are how C groups related values into one type. This easy quiz covers declaring and initialising structs, copying them, nesting them, the -> operator and typedef, with a look at why struct sizes can surprise you.

Facile 10 questions ~5 minutes Réussi à partir de 80 % C17

Choisissez un mode

Vous jouez en invité : connectez-vous pour garder votre XP et votre série.

Exemple de question

Question 1 sur 10

What does this print?

#include <stdio.h>

struct point {
    int x;
    int y;
};

int main(void) {
    struct point p = {3, 7};
    printf("%d %d\n", p.x, p.y);
    return 0;
}
Voir la réponse

A. 3 7 A brace initializer fills the members in the order they are declared, so x gets 3 and y gets 7.

Ce que couvre ce quiz

  • Declaring structs and initialising them, including designated initializers
  • Struct assignment copies every member
  • Nested structs and the -> operator
  • typedef for shorter type names
  • Padding and why you cannot compare structs with ==

Questions fréquentes

Faut-il un compte ?

Non. Tout le monde peut jouer. Connectez-vous pour garder votre XP, votre série, vos badges et votre historique.

Puis-je le refaire ?

Oui. Votre meilleur score est conservé, et les questions comme les réponses sont mélangées à chaque fois.