What is character set, c tokens and constant in c programming language?

1) Character set

The characters that can be used to form words, numbers and expressions depend upon the computer on which the program is run. However, a subset of characters is available that can be used on most personal, micro, mini and mainframe computers. The characters in C are grouped into the following categories:

1. Letters

2. Digits

3. Special characters

4. White spaces

 

 

2) Trigraph Characters

Many non-English keyboards do not support all the characters. ANSI C introduces the concept of "trigraph" sequences to provide a way to enter certain characters that are not available on some keyboards. Each trigraph sequence consists of three characters (two question marks followed by another character).

For example, 

, comma

.period

; semicolon

: colon

? question mark

"quotation mark

 

3) C Tokens

In a passage of text, individual words and punctuation marks are called tokens. Similarly, in a C program the smallest individual units are known as C tokens. C has six types of tokens as shown in the following chart. C programs are written using these tokens and the syntax of the language.

 

4) Keywords and identifier

Every C word is classified as either a keyword or an identifier. All keywords have fixed meanings and these meanings, cannot be changed. Keywords serve as basic building blocks for program statements. All keywords must be written in lowercase. Some compilers may use additional keywords that must be identified from the C manual.

For example,

Break, case, char, float, return, void etc...

Identifiers refer to the names of variables, functions and arrays. These are user-defined names and consist of a sequence of letters and digits, with a letter as a first character. Both uppercase and lowercase letters are permitted, although lowercase letters are commonly used. The underscore character is also permitted in identifiers. It is usually used as a link between two words in long identifiers.

Rules for Identifiers

1. First character must be an alphabet (or underscore).

2. Must consist of only letters, digits or underscore.

3. Only the first 31 characters are significant.

4. Cannot use a keyword.

5. Must not contain white space.

 

5) CONSTANTS

Constants in C refer to fixed values that do not change during the execution of a program. Supports several types of constants, as illustrated in flow chart.

a) Integer Constants

An integer constant refers to a sequence of digits. There are three types of integers, namely decimal integer, octal integer and hexadecimal integer.

b) Real Constants

Integer numbers are inadequate to represent quantities that vary continuously, such as distances, heights, temperatures, prices, and so on. These quantities are represented by numbers containing fractional parts, like 17.548. Such numbers are called real (or floating point) constants.

c) Single Character Constants

A single character constant (or simply character constant) contains a single character en closed within a pair of single quote marks. Example of character constants are:

'5 5'      'X'     '**'

Note that the character constant '5' is not the same as the number 5. The last constant is a blank space.

Character constants have integer values known as ASCII values.

d) String Constants

A string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters and blank space. Examples are:

"Hello!" "1987" "WELL DONE" "?!" "5+3" "X"

 

e) Backslash Character Constants.

C supports some special backslash character constants that are used in output functions. For example, the symbol '\n' stands for newline character. 

 

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

About Author