Blocks and Scope - Programming Tutorials

Programming Tutorials

Programming Tutorials

Ads Here

Blocks and Scope

C is a block structured language. Blocks are enclosed by { and }. Blocks can be defined wherever a C statement could be used. No semi-colon is required after the closing brace of a block. Variable Scope refers to where variables is declared. Global variables Global variable are declared outside any functions, usually at top of program. they can be used by later blocks of code: int g; int main(void) { g = 0; } Local variables Variables that are declared inside a function or block are local variables. The scope of local variables will be within the function only. These variables are declared within the function and can't be accessed outside the function. void main() { int g; g=2; printf(''g= %d'',&g); }

No comments:

Post a Comment