C Variables Literals
C Variables Literals
Variables
In programming, a variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name (identifier).
Variable names are just the symbolic representation of a memory location. For example:
1. int playerScore = 95;
Here, playerScore is a variable of int type. Here, the variable is assigned an integer
value 95.
1. char ch = 'a';
2. // some code
3. ch = 'l';
C is a strongly typed language. This means that the variable type cannot be changed
once it is declared. For example:
1. Integers
An integer is a numeric literal(associated with numbers) without any fractional or
exponential part. There are three types of integer literals in C programming:
decimal (base 10)
octal (base 8)
hexadecimal (base 16)
For example:
In C programming, octal starts with a 0, and hexadecimal starts with a 0x.
2. Floating-point Literals
A floating-point literal is a numeric literal that has either a fractional form or an exponent
form. For example:
-2.0
0.0000234
-0.22E-5
Note: E-5 = 10-5
3. Characters
A character literal is created by enclosing a single character inside single quotation
marks. For example: 'a', 'm', 'F', '2', '}' etc;
4. Escape Sequences
Sometimes, it is necessary to use characters that cannot be typed or has special
meaning in C programming. For example: newline(enter), tab, question mark etc.
Escape
Sequences Character
\b Backspace
\f Form feed
\n Newline
\r Return
\t Horizontal tab
\v Vertical tab
\\ Backslash
\? Question mark
\0 Null character
Escape Sequences
5. String Literals
A string literal is a sequence of characters enclosed in double-quote marks. For
example:
Constants
If you want to define a variable whose value cannot be changed, you can use
the const keyword. This will create a constant. For example,
1. const double PI = 3.14;
Notice, we have added keyword const.
Here, PI is a symbolic constant; its value cannot be changed.
1. const double PI = 3.14;
2. PI = 2.9; //Error
You can also define a constant using the #define preprocessor directive.