0
0
Cprogramming~5 mins

Constants and literals - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a constant in C programming?
A constant is a value that cannot be changed during the execution of a program. It is fixed and used to represent data that should remain the same.
Click to reveal answer
beginner
What is a literal in C?
A literal is a fixed value written directly in the code, like numbers (e.g., 5), characters (e.g., 'a'), or strings (e.g., "hello").
Click to reveal answer
beginner
How do you declare a constant integer named MAX in C?
Use the keyword <code>const</code>: <br><code>const int MAX = 100;</code> This means MAX cannot be changed later.
Click to reveal answer
intermediate
What is the difference between a constant and a literal?
A literal is a fixed value written directly in the code. A constant is a named value that cannot change and is usually defined using const or #define.
Click to reveal answer
intermediate
What does the #define directive do in C?
It defines a constant value or macro before compilation. For example, #define PI 3.14 replaces all occurrences of PI with 3.14 in the code.
Click to reveal answer
Which keyword is used to declare a constant variable in C?
Alet
Bconst
Cstatic
Dvar
What is the type of the literal 'A' in C?
Aint
Bfloat
Cstring
Dchar
What will happen if you try to change a const variable's value?
AThe compiler will give an error
BThe value will change at runtime
CThe program will compile and run normally
DThe program will crash
Which of these is a valid integer literal in C?
A123
B"123"
C'123'
D12.3
What does this line do? #define SIZE 10
ACreates a function named SIZE
BDeclares a variable SIZE with value 10
CDefines a constant SIZE with value 10
DAllocates memory of size 10
Explain the difference between a constant and a literal in C.
Think about how you use names versus direct values in code.
You got /3 concepts.
    How do you declare a constant integer and why would you use it?
    Consider protecting important values from accidental changes.
    You got /4 concepts.