How user can be misled by variable names

PHOTO EMBED

Tue Sep 05 2023 09:01:48 GMT+0000 (Coordinated Universal Time)

Saved by @tkvenki #c

#include <stdio.h>

// Global variable with global scope
int globalVar = 10;

// Function with function scope
void foo() {
    //Note that we are redefining the variable with same name as teh global
    int globalVar;

    //The local Variable is incremented!!!. Not the global one.
    globalVar++;
}

int main() {

    foo();  // Call the function with function scope variable

    printf("\n%d\n", globalVar);


}
content_copyCOPY