Constants
1. What is a constant in C?
a) A variable whose value can be changed
b) A fixed value that does not change during program execution
c) A loop counter
d) A macro with a function
Answer: b) A fixed value that does not change during program
execution
2. Which keyword is used to declare a constant variable?
a) final
b) static
c) const
d) define
Answer: c) const
3. Which of the following defines a symbolic constant?
a) const int rate = 5;
b) #define RATE 5
c) final rate = 5;
d) rate := 5;
Answer: b) #define RATE 5
4. Can constants be declared using the const keyword?
a) Yes
b) No
Answer: a) Yes
5. Which of the following is a valid constant declaration?
a) const int PI = 3.14;
b) int const = 5;
c) #const PI = 3.14;
d) define PI = 3.14;
Answer: a) const int PI = 3.14;
6. What happens if you try to modify a const variable?
a) It compiles and runs
b) Compiler gives an error
c) It gives a warning
d) It auto-corrects the value
Answer: b) Compiler gives an error
7. What is the difference between #define and const?
a) #define is type-checked
b) const is pre-processed
c) const is type-checked, #define is not
d) Both are the same
Answer: c) const is type-checked, #define is not
8. Which of these is a floating-point constant?
a) 5
b) ‘A’
c) 5.0
d) "Hello"
Answer: c) 5.0
9. What is the scope of a constant defined with #define?
a) Block
b) Function
c) File
d) Local
Answer: c) File
10. Can we assign a value to a constant inside a function later?
a) Yes
b) No
Answer: b) No