Variable Hiding - C Language Basics

C examples for Language Basics:Variable

Introduction

When a variable in the inner block has the same name with a variable in the outer block, the variable in the inner block shadows the variable in the outer block.

Demo Code

#include <stdio.h>

int main(void)
{
    int x;/*  w  w w.ja v a  2 s . com*/

    x = 10;

    if (x == 10) {
        int x; /* this x hides the outer x */

        x = 99;
        printf("Inner x: %d\n", x);
    }
    printf("Outer x: %d\n", x);

    return 0;

}

Related Tutorials