ควิซ C: Scope & Lifetime

This C quiz tests scope (where a name is visible) and lifetime (how long the variable exists). You will trace shadowed variables in nested blocks, loops and functions, and spot dangling pointers and names used out of scope.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% C17

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What does this print?

#include <stdio.h>

int main(void) {
    int x = 1;
    {
        int x = 2;
        printf("%d ", x);
    }
    printf("%d\n", x);
    return 0;
}
ดูเฉลย

A. 2 1 The inner block declares a new x that shadows the outer one until the closing brace. The outer x was never changed, so the second printf prints 1.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • Block scope and shadowing
  • Loop variables declared in for
  • Global variables and function parameters
  • Automatic variables are recreated each time
  • Dangling pointers to local variables

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง