#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);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter