1. What is a variable in C programming?
Answer:
Explanation:
A variable in C programming is a storage location that is assigned a name. It can store data values.
2. Which of the following is a valid variable name in C?
Answer:
Explanation:
Variable names in C can start with an underscore or a letter and can include numbers but cannot start with a number or include special characters like '-'.
3. How do you declare an integer variable named 'age' in C?
Answer:
Explanation:
In C, an integer variable is declared with the keyword 'int' followed by the variable name, such as 'int age;'.
4. What will be the initial value of an uninitialized integer variable in C?
Answer:
Explanation:
Uninitialized variables in C have an undefined value, often a random number, based on whatever is in the memory location.
5. How do you initialize a float variable 'temp' with the value 23.5 in C?
Answer:
Explanation:
In C, float literals should be suffixed with 'f' or 'F' to distinguish them from double. So, 'float temp = 23.5f;' is correct.
6. Which of the following is the correct way to declare a character variable with the value 'A'?
Answer:
Explanation:
A character variable is declared with the 'char' keyword and initialized with a single character enclosed in single quotes.
7. What is the correct syntax to declare a constant integer variable 'MAX' with value 100 in C?
Answer:
Explanation:
The 'const' keyword is used to declare a constant variable in C. Alternatively, '#define' could also be used as a preprocessor directive.
8. Which of the following is used to define a symbolic constant in C?
Answer:
Explanation:
'#define' is a preprocessor directive used to define symbolic constants in C.
9. What is the default value of a global integer variable in C?
Answer:
Explanation:
Global and static variables in C are automatically initialized to zero.
10. What data type would you use to store a person's first name in C?
Answer:
Explanation:
A string, like a person's first name, is stored in a char array in C.
11. How do you declare an array of 10 integers in C?
Answer:
Explanation:
Arrays in C are declared with the data type, followed by the array name and size in square brackets.
12. Which of the following operators is used to access the value at a specific address in a pointer?
Answer:
Explanation:
The '*' operator is used to dereference a pointer, i.e., to access the value at the memory address stored in the pointer.
13. What is the output of the following C code: int x = 10; printf("%d", x);
Answer:
Explanation:
The printf function prints the value of the 'x' variable, which is 10.
14. What is the purpose of the 'sizeof' operator in C?
Answer:
Explanation:
The 'sizeof' operator is used to determine the size, in bytes, of a variable or data type.
15. What is the correct way to assign a new value to an existing variable in C?
Answer:
Explanation:
In C, a variable is assigned a value using the '=' operator after declaring it.
16. What is the scope of a local variable in C?
Answer:
Explanation:
A local variable in C is only accessible within the function in which it is declared.
17. Which of the following is not a valid data type in C?
Answer:
Explanation:
C does not have a native 'string' data type. Strings are represented as arrays of characters.
18. What does the following declaration mean? int *ptr;
Answer:
Explanation:
In C, the '*' symbol is used in the declaration to indicate that the variable is a pointer to the specified data type.
19. What is the result of the following expression in C: 5 + 3 * 2?
Answer:
Explanation:
According to the order of operations in C, multiplication is performed before addition, so the expression evaluates to 5 + (3 * 2) = 11.
20. What is the purpose of the 'return' statement in a C function?
Answer:
Explanation:
The 'return' statement in a C function is used to return control to the calling function, optionally returning a value.