Elements of C

c
C Programming Tutorial

Elements of the C Language - Character Set, Keywords, and Identifiers

Every language has some basic elements (alphabets, words, etc.) and grammatical rules. Before understanding programming, it is necessary to know the basic elements of C language. These basic elements are character set, variables, data types, constants, keywords (reserved words), variable declaration, expressions, statements etc. All of these are used to create a- C program.

C Character Set

Following are some character sets that we use in C programs.

Alphabets

  • A, B, C …………… Z.
  • a, b, c ……………. Z

Number and Digits

  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Special Characters

Character Sets Meaning Character Sets Meaning

+

Plus Sign

-

Minus

*

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

'

Double Quotes

"

Double Quotes

:

Colon

;

Semicolon

?

Question Mark

!

Exclamation Sign

&

Ampersand

|

Vertical Bar

@

At The Rate

^

Caret Sign

$

Dollar Sign

#

Hash Sign

~

Tilde Sign

'

Back Quotation Mark

Execution Characters / Escape Sequences

Characters are printed on the screen through the keyboard but some characters such as newline, tab, backspace cannot be printed like other normal characters. C supports the combination of backslash (\) and some characters from the C character set to print these characters.

These. character combinations are known as escape sequences and are represented by two characters. The first character is “\” and second character is from the C character set. Some escape sequences are given below-

Escape Sequences Meaning ASCII Value Purpose
\b
Backspace
008
Moves the cursor to the previous position of the current line
\a
Bell(alert)
007
Produces a beep sound for alert
\r
carriage return
013
Moves the cursor to beginning of the current line.
\n
newline
010
Moves the cursor to the beginning of the next line
\f
form feed
012
Moves the cursor to the initial position of the next logical page.
\0
null
000
Null
\v
vertical tab
011
Moves the cursor to next vertical tab position
\t
Horizontal tab
009
Moves the cursor to the next horizontal tab position.
\\
backslash
092
Presents a character with backslash ( \ )

Blank, horizontal tab, vertical tab, newline, carriage return, form feed are known as whitespace in C language.

Trigraph Characters

There is a possibility that the keyboard does not print some characters. C supports the facility of “trigraph sequence” to print these characters. These trigraph sequences have three characters. First two an ‘??’ and third character is any character from C character set. Some trigraph sequences are as given below-

Table Header Table Header
??<
{ Left Brace
??>
} Right Brace
??(
[ Left Bracket
??)
] Right bracket
??!
| Vertical Bar
??/
\ Backslash
??=
# Hash Sign
??-
~ Tilde Sign
??'
^ Caret

Delimiters

delimiter is a sequence of one or more characters that we used for different purposes. These are as given below-

Delimiters
:
Colon
Used for Label
;
Semicolon
End of Statement
()
Parentheses
Used for Expression
[]
Square Brackets
Used for Array
{}
Curly Braces
Used for Block of Statements
#
Hash
Preprocessor Directives
,
Comma
Variable Delimiter

Reserved Words / Keywords

There are certain words that are reserved for doing specific tasks. These words are known as keywords and they have standard, predefined meaning in C. They are always written in lowercase. There are only 32 keywords available in C which are given below

Keywords
auto
break
case
char
const
continue
default
do
double
else
enum
extern
flot
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
unioun
unsigned
void
volatile
while

Identifiers

All the words that we use in our C programs it is either keywords or identifiers. Keywords are Predefined and cannot be changed by the user, while identifiers are user defined words and are used to give names to entities like variables, arrays, functions, structures etc. Rules for naming identifiers are given below-

  1. The first character in an identifier must be an alphabet or an underscore and can be followed only by any number alphabets, or digits or underscores.
  2. They must not begin with a digit.
  3. Uppercase and lowercase letters are distinct. That is, identifiers are case sensitive.
  4. Commas or blank spaces are not allowed within an identifier.
  5. Keywords cannot be used as an identifier.
  6. Identifiers should not be of length more than 31 characters.
  7. Identifiers must be meaningful, short, quick, and easily typed and easily read.

The identifiers are generally given meaningful names. Some examples of valid identifier names.

Value      a               net-pay                  rec1       _data      MARKS

some examples of invalid identifier names are-

5bc         First character should be an alphabet or underscore

Int           int is a keyword

rec#       # is a special character

avg no   blank space is not permitted