Variables and Keywords
Building blocks of C data storage and language syntax
Character Set
Alphabets
- Uppercase: A – Z
- Lowercase: a – z
Digits
- Numeric digits: 0 – 9
Special Characters
- ~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ? \ | : ; " '
White Spaces
- Horizontal tab
- Carriage return
- New line
- Form feed
Identifiers
An Identifier is the name of a variable, function, or array that is made up from a combination of alphabets, digits, and underscore.
Variables & Naming Rules
A Variable is a name given to a memory location where data can be stored and manipulated during program execution.
- The first character must be an alphabet (letter) or an underscore.
- Keywords are reserved and cannot be used as variable names.
- White spaces and blanks are not allowed in variable names.
- C is case-sensitive (UPPERCASE and lowercase letters are treated distinctly).
- Only the underscore (_) special symbol is permitted between characters.
- The identifier length may be up to 31 characters (traditionally the first 8 characters were significant to early compilers).
Local Variables
Local variables are declared within the body of a function and can only be accessed within that function block:
void main() {
int a, b, c; // Local to main()
}
void func() {
int x, y, z; // Local to func()
}Note
Global Variables
A global variable is declared outside of any program function, usually at the beginning of the program file after preprocessor directives:
int a, b, c; // Global variables
void main() {
// Can access a, b, c
}
void func1() {
// Can also access a, b, c
}Note
Keywords in C
Keywords are system-defined reserved identifiers with fixed meanings that cannot be altered or used as variable names.
- Keywords are system-defined identifiers.
- All keywords have fixed meanings that do not change.
- White spaces are not allowed within keywords.
- A keyword may not be used as an identifier.
- It is strongly recommended that keywords always be written in lowercase letters.
Escape Sequence Characters (Backslash Constants)
C supports escape sequences used to perform formatting and special tasks, also known as 'Backslash characters':
\n\b\t\f