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?
✗ Incorrect
Global variables are declared outside all functions and can be accessed anywhere after their declaration.
What is the scope of a variable declared inside a for loop in C?
✗ Incorrect
Variables declared inside the for loop block have block scope and are accessible only inside that block.
If a local variable and a global variable share the same name, which one is used inside the function?
✗ Incorrect
The local variable hides the global variable inside the function scope.
What does the static keyword do when used with a variable inside a function?
✗ Incorrect
Static variables inside functions retain their value between calls and are only accessible inside that function.
Which of these is NOT a valid scope type in C?
✗ Incorrect
C does not have class scope because it is not an object-oriented language.
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.