Elements of the C Language - Identifiers, Keywords, Data types and Data objects
This article deals with basic elements, which are used to create a C program. These elements are - the valid character set, identifiers, keywords, basic data types and their representation, constants and variables.
The C Character Set
C uses the uppercase English alphabets A to Z, the lowercase letters a to z, the digits 0 to 9, and certain special characters as building blocks to form basic program elements viz. constants, variables, operators, expressions and statements.
The special characters are listed below:
| ! | * | + | \ | " | < |
| # | ( | = | | | { | > |
| % | ) | ~ | ; | } | / |
| ^ | - | [ | : | , | ? |
| & | - | ] | ' | . | (blank) |
Most versions of the language also allow some other characters, such as @ and $, to be included within strings and comments.
In addition certain combinations of these characters, such as '\b', '\n' and '\t', are used to represent special condition such as backspace, newline and horizontal tab, respectively. These character combinations are known as escape sequences.
Identifiers and Keywords
Identifiers are names given to various items in the program, such as variables, functions and arrays. An identifier consists of letters and digits, in any order, except that the first character must be a letter. Both upper and lowercase letters are permitted. Upper and lowercase letters are however not interchangeable (i.e., an uppercase letter is not equivalent to the corresponding lowercase letter). The underscore character (_) can also be included, and it is treated as a letter. Keywords like if, else, int, float, etc., have special meaning and they cannot be used as identifier names.
The following are examples of valid identifier names: A, ab123, velocity, stud_name, circumference, Average, TOTAL
The following names are not valid identifiers:
| 1st | - the first character must be a letter |
|---|---|
| "Jamshedpur" | - illegal characters (") |
| stud-name | - illegal character (-) |
| stud name | - illegal character (blank space) |
Although an identifier can be arbitrarily long, most implementations recognize typically 31 characters. There are some implementations, which recognize only eight characters. The ANSI standard recognizes 31 characters. If a system recognizes only 8 characters and if you use a variable name with more than 8 characters, only the first 8 characters will be taken, the rest will be ignored. Thus, average_of_numbers and average_ will both be recognized as average_. It is therefore safer to try and use short meaningful names for your identifiers.
Walang komento:
Mag-post ng isang Komento