Which of the following best explains why variables are used in C programming?
Think about how programs remember information while running.
Variables hold data that can change while the program runs, allowing the program to work with different values.
What will be the output of this C program?
#include <stdio.h> int main() { int age = 25; age = age + 5; printf("%d", age); return 0; }
Look at how the variable age changes before printing.
The variable age starts at 25, then 5 is added, so the output is 30.
What error will this C code produce?
#include <stdio.h> int main() { int number; printf("%d", number); return 0; }
Think about what happens when you print a variable without giving it a value first.
The variable 'number' is declared but not initialized, so it contains garbage data. Printing it shows an unpredictable value.
Which of the following is a correct way to declare a variable in C?
Remember variable names cannot start with a number and must match the data type.
Option B correctly declares an integer variable named 'number' and assigns it the value 10.
Consider this C program. How many variables are declared and used?
#include <stdio.h> int main() { int a = 5; int b = 10; int c = a + b; printf("%d", c); return 0; }
Count each variable declared with int.
Variables a, b, and c are declared and used, totaling 3.