C Language Elements Character Sets in C Programming

C Language Elements

Before moving further in C programming, we need to know the basic elements of this language. C language elements are mainly the following elements such as variables, constants, keywords, functions, declaration of the variable inside and outside the function, manipulation of any programming statement, etc. In this tutorial, we will learn about these C language elements and their implementation as well.

C Language Elements: Character Set

These are the most commonly used C Language Elements. Below is the list of the character set widely used in C programs:

Alphabets

They are English language alphabets in both capital and small letters like A, B, C,……., Z, and a, b, c, ……, z.

Digits

First 10 digits of elementary mathematics from zero to nine.

Special Characters

+ plus sign– minus sign(hyphen)* asterisk% percent sign
\ Backward slash/ forward slash< less than sign= equal to sign
> greater than sign_ underscore( left parenthesis) right parenthesis
{ left braces} right braces[ left bracket] right bracket
, comma. period‘ single quotes” double quotes
: colon; Semicolon? Question mark! Exclamation sign
& ampersand| vertical bar@ at the rate^ caret sign
$ dollar# hash~ tilde` back quotation

Escape Sequences/Execution Characters

When it comes to printing a character, any character is printed through the keyboard. It is visible to us on the standard output device/screen. Still, there are some characters that cannot be printed through the keyboard. For example, the new line or backspace is the characters that the keyboard cannot print through. The C programming language supports some mechanisms through which we can print these characters. The escape sequence is that said mechanism. The escape sequence is always a combination of 2 characters. The first character will be backless and the second is the small letter from C character sets. The escape sequence is also called the execution characters. The commonly used escape sequences are:

  • \b backspace: Used for the backspace.
  • \n newline: Beginning of the newline.
  • \o null: Null
  • \v vertical tab: Next vertical tab position.
  • \t Horizontal tab: Next horizontal tab position.

Delimiters

These are used to give the proper syntax to a program. Commonly used delimiters are listed below.

  1. : Colon – used for the label.
  2. ; Semicolon – used to end the statement.
  3. () parentheses – used in an expression.
  4. [] square brackets – used for the Array representation.
  5. {} curly braces – Represent a block of statements.
  6. # hash – preprocessor directive.
  7. , comma – used as the separator.

Keywords/Reserved Words

Keywords are basic English Like Words. It is always written in a small letter and is of special importance in C programming. As their meaning is already defined and is used only for a defined purpose. that is why they are called keywords. Because C is a small language. It supports only 32 keywords. Each keyword is listed below.
double, float, int, short, struct, unsigned, auto, const, continue, default, else, enum, for, goto, long, register, signed, sizeof, switch, typedef, void, break, case, volatile, if, return, static, union, while, char, do, extern.

Trigraph Characters

The working of these characters is the same as of escape sequence. But its syntax is slightly different from the escape sequence. It is a basic three-character combination in which the first two characters are question marks and the third is a special character. This combination of three characters is used to print those characters/symbols that cannot be printed directly with the keyboard.

  1. ??< prints  { left brace.
  2. ??> prints  } right brace.
  3. ??( prints  [ left bracket.
  4. ??) prints  ] right bracket.
  5. ??! prints  | vertical bar
  6. ??/ prints  \ backslash
  7. ??= prints  # hash symbol

Identifiers

These c language elements are the user-defined special words. They are used to give the name to entities like variables, functions, constants, array, and structures. to name these entities some rules must have to follow.

  1. The name consists of only alphabets, digits, and underscore sign( _ ).
  2. Alphabets can be used in both uppercase and lowercase.
  3. The first character must be an alphabet or underscore.
  4. The keywords are not allowed.
  5. Blank spaces and special characters are not allowed.
  6. Since C language is case sensitive, hence the lowercase and uppercase letters are always considered different. For example next, Next and NEXT are the three different identifiers.
  7. An identifier name may be arbitrarily long. Some implementations recognize the first eight characters. Though most implementations recognize 31 characters. ANSI standard compilers recognize 31 characters.

Example of Valid Identifiers

Next, u, _cool, etutororg1, e_tutor_org, ETUTORORG.

Example of Invalid Identifiers

  1. 2ab – First character must be the underscore sign or an alphabet.
  2. break – This is the keyword.
  3. ab# – # is a special character.
  4. avg sal – Blank space is not allowed.

Leave a Comment

Your email address will not be published. Required fields are marked *