内部块与外部块中的变量名称相同时覆盖

#include <stdio.h>

int main(){
    int x = 30;      // original x

    printf("x in outer block: %d at %p/n", x, &x);
    {
        int x = 77;  // new x, hides first x
        printf("x in inner block: %d at %p/n", x, &x);
    }
    printf("x in outer block: %d at %p/n", x, &x);

    while (x++ < 33) // original x
    {
        int x = 100; // new x, hides first x 
        x++;
        printf("x in while loop: %d at %p/n", x, &x);
    }
    printf("x in outer block: %d at %p/n", x, &x);

    return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266434.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论