Constants
Learn about different types of constants in C.
Constants are values that do not change after they have been defined. These values can be of different types.
Numeric constants
An example of an int
constant is the number 1234
. An example of a floating-point constant (by default typed as a double
) is 123.4
. Another example of a floating-point constant is 2e-3
(which represents 2 x 10-3 in scientific notation). We can also write numbers in octal or hexadecimal representations instead of decimal: octal by using a leading zero (0
) and hexadecimal by using a leading zero followed by an x (0x
). Decimal 31
can be written as 037
in octal and 0x1f
or 0X1F
in hexadecimal. Here are some examples of how numeric constants are created and then assigned to variables:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy