Understanding Constants and Variables in Programming
Classified in Computers
Written on in
English with a size of 1.94 KB
Constants and Variables
Constants
Constants are quantities whose values do not change during program execution. They may be numeric, character, or string.
Numeric Constants
Numeric constants are of two types: integer and floating-point numbers.
- Integer Constants: Represent values that are counted, such as the number of students in a class. Examples include 7145, -234, and 26.
- Floating-point Constants: Used to represent values that are measured, such as height (e.g., 166.75 cm) or weight (e.g., 82.6 kg).
Character and String Constants
- Character Constant: A symbol from the C character set (digits 0-9, letters A-Z, a-z, punctuation, and special symbols). These are enclosed in single quotes, such as 'a' or 's'.
- String Constant: A sequence of characters