C クイズ: Unions & Enums

This C quiz covers enums, which give names to integer constants, and unions, whose members share the same memory. You will predict enum values, build a tagged union and learn what C does and does not promise about them.

ふつう 10問 約6分 合格ライン 80% C17

モードを選ぶ

ゲストとしてプレイ中です。ログインすると XP と連続記録が保存されます。

例題

第1問 / 全10問

What does this print?

#include <stdio.h>

enum color { RED, GREEN, BLUE };

int main(void) {
    printf("%d %d %d\n", RED, GREEN, BLUE);
    return 0;
}
答えを見る

D. 0 1 2 Enum constants are plain integers that start at 0 and go up by one. printf() prints numbers, C has no built-in way to get an enum's name as text.

このクイズの内容

  • Default and explicit enum values
  • Enums in switch and the COUNT trick for array sizes
  • Why enum constants live in one shared namespace
  • Union members share storage, so the last write wins
  • Tagged unions and the size of a union

よくある質問

アカウントは必要ですか?

いいえ、誰でも遊べます。ログインすると XP、連続記録、バッジ、履歴が保存されます。

何度でも挑戦できますか?

はい。ベストスコアが記録され、問題と選択肢は毎回シャッフルされます。