Introduction to C – Characters set

C Characters Set

Character set of C
Character Set of C Language

 

  • Characters set are used to form of words, numbers and statements.
  • Like natural languages, computer language will also have well defined characters set, which is useful to build the programs.
  • In C language used the following characters set-

1. Letters (Alphabets)

Uppercase (Capital Letters) A…Z

Lowercase (Small Letters) a…z

2. Digits 

        All decimal digits: 0,1,2,….9 (10 Digits).

3. Special Characters

C language contains the following special character in association with the letters and digits. 

 

Special Characters

Symbol         Meaning

Symbol         Meaning

~      Tilde

{      Left brace

}      Right brace

[      Left bracket

]      Right bracket

(      Lest parenthesis

)     Right parenthesis

<    Opening angle bracket

>    Closing angle bracket

*      Asterisk

+    Plus sign

/     Slash

–      Minus sign

%   Percent sign

&    Ampersand

|     Vertical bar

!     Exclamation mark

#    Number sign (Hash)

$     Dollar sign

:     Colon

^    Caret

“      Quotation mark

;     Semicolon

?     Question mark

_     Underscore

,     Comma

.     Period

\     Backslash

`     Apostrophe

=    Equal to sign

 

4. White Spaces

  1. These characters are not show on the screen (do not Display any indication)
  2. White spaces may be used to separate words.
  3. The compiler ignores white spaces unless they are a part of a string constant.
  4. White space characters are:

          – blank space

          – horizontal tab

          – vertical tab

          – carriage return

          – form feed

                             – new line

                             – Null characters

5. Trigraph Characters

  • Many non English keyboard do not support all the characters (Used only non English Keyboard)
  • ANSI C introduces the concept of “trigraph” sequences to provide a way to enter certain characters
  • Each trigraph sequence consists of three characters (two question marks followed by another character)

Example:

??=         #  number sign (hash)

??(           [   left bracket

??}          ]   right bracket

??<         {   left brace

??>         }   right brace

??/           \    back slash

C-Tokens

  • In a C program, individual words/unit and punctuation marks are called tokens.
  • C Tokens are smallest units of a program.
  • C tokens are the basic buildings blocks in C language which are constructed together to write a C program.

C tokens are six types. They are:

1. Keywords – Pre-defined/In-Built words/Fixed words/Reserved words in compilers. All keywords used in lowercase (small letters). There are 32 keywords used in C language. E.g. int, char, float, void, return, if, do, for, while.

2. Identifiers – It is user/programmer’s  define words. refers to name of variable, array, function, structure and union. E.g. a, b , name, add(), fact(), a[i] etc.

3. Constants – Refer to fixed values these values can’t change during program execution. E.g. – 34, -87, 0 (integer constant), 9.455, .0003, 5.0 (float constant), ‘a’, ‘2’, ‘*’ (chars constant), “140 abc” (string constant)

4. Operators – Symbols that perform arithmetic and logical operation. /, *, %, +, – (arithmetic operators), >, <, >=, <=, !, != (relational operators), &&, ||, ! (logical operators) etc.

5. Strings –  Group of one or more characters. Enclosed within double quotes. E,g, “Jaipur” , “123, nkgacademy.com”.

6. Special symbols – Punctuation marks. ; (semi-colon used to termination or end of statement of C statement and : is used to declare label name or label value in C.) 

Why we read and what benefits of above characters set 
and C-Tokens?
     - If we learn C characters set and C-tokens then we can write the C Language 
        Source Code (C Programs)
     - In C Program includes the following:
               1. Comments
               2. Pre-processor
               3. C-Tokens and 
               4. functions (library and user define both) 

 Explanation with Example: 
Here we given C Language code/program area and circumference of circle, in this program we 
determine or identify to different terminology used in program.
/* area and circumference of circle */
#include<stdio.h> 
#include<math.h> 
#define PI 3.14 
int main() 
{     
       float r, c, area;
       printf("Enter Radius: ");
       scanf("%f", &r);
       area = PI*pow(r,2);
       c = 2 * PI * r;
       printf("Radius of Circle = %f\n",r);
       printf("Area of circle     = %f\n",area);
       printf("Circumference   = %f\n",c);
       return 0;
}
in the above program- 
1. /* area and circumference of circle */ is the comments.
2. #include and  #define are called pre-processors.
3. stdio.h (standard input output) and math.h are header files.
4. int, float, return are keywords.
5. r, c and area are called identifiers (variable name).
6. PI is constant (float).
7. =, *, & are operators.
8. main() is user define function (compulsory function).
9. printf(), scanf() and pow() are library functions.
10. "Radius of Circle =" is string (or text message) constant.
11. {} braces, () parenthesis, ; semicolon, " and coma (,)  are punctuation symbols. 
12. %f is format specifier character used in printf() and scanf() function.

 

 

Leave a Reply