2 | Basic Elements of C Language
2.0 | Contents :
1. Characters
2. Keywords
3. Identifiers
4. Constants
5. Data Types
6. Escape Sequences
2.1 | Characters :
Characters used in C language are classified into four types :
- Letters
- Digits
- Special Characters
- White Spaces
| Characters | Elements | |
|---|---|---|
| Letters | Uppercase A - Z Lowercase a - z |
|
| Digits | 0 to 9 | |
| Special Characters | , comma | ; semicolon |
| ? question mark | $ dollar symbol | |
| # number sign | ~ tild | |
| * asterisk | + plus | |
| - minus | % percentage | |
| < less than | > greater than | |
| ! exclamation mark | ||
| White Spaces | Blank Space | New Line |
| Form Feed | Horizontal Tab | |
| Carriage Return | ||
2.2 | Keywords :
Keywords are standard predefined words to use in C language. The user/programmer can't change its meaning. Keywords are always written in the lower case. Keywords given below are used in C language :
| Keywords of C Language | |||
|---|---|---|---|
| switch | for | char | default |
| while | include | nested | int |
| boolean | case | sizeof | do |
| double | void | const | break |
| continue | go to | for | if |
| else | float | long | char |
| auto | static | signed | volatile |
| register | union | short | struct |
2.3 | Identifiers :
Names of variables, functions or arrays are called as identifiers. Identifiers are defined by user (for eg.: int a ; here, a is the name of variable of integer data-type defind/written by user/programmer).
Rules for naming of identifiers :
- Identifiers are formed with alphabates, digits and only one special character i.e. underscore ( _ ).
- The first character of an identifier must be an alphabate no matter it is in uppercase or in lowercase.
- No special characters are usable for identifiers except underscore.
- White spaces aren't allowed in between the naming of identifiers.
- Identifiers are case sensitive (i.e. main is different from MAIN).
| Valid Identifiers | Invalid Identifiers |
|---|---|
| app12 | 12app |
| app_11 | app _ 11 |
| App32 | App 32 |
2.4 | Constants :
A constant is a quantity whose value does not change during the execution of C program. There are three types of constants in C language :
- Numeric Constants
- Character Constants
- String Constants
1. Numeric Constants :
This constant is made up of digits. There are two types of numeric constant :
- Integer or Fixed Point Constants :
It is made up of only integer digits i.e there is no decimal point in integer or fixed point constants. Its range is from -32,768 to 32,767. For eg.: -121, 546, etc.
- Real or Floating Point Constants :
It consist of any number with one decimal point. For eg.: 54.746
2. Character Constants :
This type of constants are used to represent an alphabet. Alphabet used for character constant is written in single quotes. For eg.: 'A', 'b', etc.
3. String Constants :
This type of constants are used to represent a word (i.e. set of characters) in double quotes. For eg.: "Study", "language", etc.
2.5 | Data Types :
Data-types are used to store various types of data that is processed by the program. Data-type is used with the name of variables, functions or arrays to define there data-types. Data-types used in C language are given below :
| Data Type | Type of Variable | Size (in bytes) |
Range |
|---|---|---|---|
| char | Character | 1 | -128 to 127 |
| unsigned char | Unsigned Character | 0 to 255 | |
| int | Integer | 2 | -32,768 to 32,767 |
| short / short int | Short Integer | 1 | |
| long | Long Integer | 4 | -2,14,74,83,648 to 2,14,74,83,648 |
| unsigned int | Unsigned Integer | 2 | 0 to 65,535 |
| unsigned short | Unsigned Short Integer | 2 | |
| unsigned long | Unsigned Long Integer | 4 | 0 to 4,29,49,67,295 |
| float | Floating Point Digits | 3.4e-38 to 3.4e+38 | |
| double | 8 | 1.7e-308 to 1.7e+308 |
2.6 | Escape Sequences :
| Escape Sequences | Meaning |
|---|---|
| \\ | \ character |
| \' | ' character |
| \" | " character |
| \? | ? character |
| \a | alert OR bell |
| \b | backscape |
| \f | form feed |
| \n | new line |
| \r | carriage return |
| \t | horizontal tab |
| \v | vertical tab |
| \ooo | octal number of one to three digits |
Comments
Post a Comment