0
0
Cprogramming~5 mins

Scope of variables - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the scope of a variable in C?
The scope of a variable in C is the part of the program where the variable can be accessed or used.
Click to reveal answer
beginner
What is the difference between local and global variables?
Local variables are declared inside a function and can only be used within that function. Global variables are declared outside all functions and can be used anywhere in the program after their declaration.
Click to reveal answer
intermediate
What happens if a local variable and a global variable have the same name?
The local variable will hide or override the global variable inside its scope (usually inside the function). Outside the function, the global variable is used.
Click to reveal answer
beginner
What is block scope in C?
Block scope means a variable declared inside a pair of braces { } is only accessible inside those braces.
Click to reveal answer
intermediate
What is the scope of a static variable inside a function?
A static variable inside a function keeps its value between calls but is only accessible inside that function.
Click to reveal answer
Where can a global variable be accessed in a C program?
AOnly inside the block where it is declared
BOnly inside the function where it is declared
CAnywhere in the program after its declaration
DNowhere, global variables do not exist in C
What is the scope of a variable declared inside a for loop in C?
AOnly inside the for loop block
BEntire program
COnly inside the function containing the loop
DGlobal scope
If a local variable and a global variable share the same name, which one is used inside the function?
ALocal variable
BGlobal variable
CBoth variables are used simultaneously
DCompilation error
What does the static keyword do when used with a variable inside a function?
AMakes the variable global
BMakes the variable accessible only outside the function
CDeletes the variable after the function ends
DKeeps the variable value between function calls and limits scope to the function
Which of these is NOT a valid scope type in C?
ALocal scope
BClass scope
CBlock scope
DGlobal scope
Explain the difference between local and global variables in C and give an example of each.
Think about where the variables are declared and where they can be used.
You got /4 concepts.
    Describe what happens when a local variable has the same name as a global variable in C.
    Consider which variable the program uses inside the function.
    You got /3 concepts.