C Language
Fundamentals
Unit 1
Steps in learning any Language
Alphabets - Words Sentences Paragraph
Steps in Learning C Language
Data Types,
Alphabets, digits, Constants, Instructions Program
Special characters Variable,
Keywords
Character Set
• The Character that can be used to form words,
numbers and expression forms the character set
• C has its own Vocabulary and Grammar.
• A character denotes any alphabet, digit or
special symbol used to represent information.
Upper Case Letters
American Standard Code for Information Interchange
ANSI C - American National Standard Institute
Alphabets ASCII Value
A 65 N 78
B 66 O 79
C 67 P 80
D 68 Q 81
E 69 R 82
F 70 S 83
G 71 T 84
H 72 U 85
I 73 V 86
J 74 W 87
K 75 X 88
L 76 Y 89
M 77 Z 90
Lower Case Letters
Lowercase letter:
Alphabets ASCII Value
n 110
a 97
o 111
b 98
p 112
c 99
q 113
d 100
r 114
e 101
f 102 s 115
g 103 t 116
h 104 u 117
i 105 v 118
j 106 w 119
k 107 x 120
l 108 y 121
m 109 z 122
Digits
Digits ASCII Value
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
Special Characters
Special character ASCII Value Character represented
! 32 Exclamation mark
” 34 Quotation mark
# 35 Number sign
$ 36 Dollar Sign
% 37 Percent sign
& 38 Ampersand
( 40 Left parenthesis
) 41 Right parenthesis
* 42 Asterisk
+ 43 Plus sign
Cont…
, 44 Comma
- 45 Mins sign
. 46 Period
/ 47 Slash
: 58 Colon
; 59 Semicolon
< 60 Opening angle bracket
(or) less then
sign
= 61 Equal sign
> 62 Closing angle bracket (or)
Greater than sign
? 63 Question mark
Cont….
@ 64 at symbol
[ 91 Left bracket
\ 92 Black slash
] 93 Right bracket
^ 94 Caret
_ 95 Under score
{ 123 Left brace
| 124 Vertical bar
} 125 Right brace
~ 126 Tilde
Escape Sequence
• Certain ASCII character are unprintable which means they are not
displayed on the screen or printer.
• Those character performed other function aside from displaying text.
Eg
✔ backspacing
✔ moving to a newline etc
• These are always represented by a combination of backslash(\)
followed by a character.
• These characters combination are called as Escape sequence.
Escape Sequence
Escape sequence ASCII Value Character represented
\0 00 Null
\a 07 Alarm (Beep Bell)
\b 08 Back space
\t 09 Horizontal tab
\n 10 New line
\v 11 Vertical tab
\f 12 Form feed
\r 13 Carriage return
\’’ 34 Double quote
\’ 39 Single quote
\? 63 Question mark
\\ 92 Black slash
C Tokens
❖ In a passage of text, individual words and punctuation
marks are called tokens. Similarly, in C programming the
smallest individual units are known as C tokens.
❖ C language has six types of tokens, and programs are
written using these tokens and the syntax of the
language.
Types of C Tokens
Keywords Identifiers Constants Strings Special Operators
Symbols
Keywords
• Keywords serves as the building blocks for a program statements.
All keywords have a fixed meaning and cannot be changed.
• Keywords cannot be used as normal identifier names.
• All C keywords must be written in lowercase letters.
• ANSI C has 32 keywords.
ANSI C Keywords
auto do goto signed unsigned
break double if sizeof void
case else int static volatile
char enum long struct while
const extern register switch
continue float return typedef
default for short union
IDENTIFIERS
✔Identifier refers to the name of variables, functions and arrays. These are
user defined names and consists of a sequence of letters and digits.
✔ Both uppercase and lowercase letters can be used, and c language is case
sensitive. A special symbol underscore ( _ ) is also permitted.
✔ Rules For Identifiers
❖ First character must be an alphabet or an underscore.
❖ Must consist of only letters, digits or underscore.
❖ Should not be a keyword and should not have any blank space.
❖ No two successive undrescores are allowed.
❖ Only first 31 characters are siginificant.
✔ Example:- int num; int NUM;
✔ char name;
Where num and name are identifier names.
Constants
✔Constants refers to fixed values that do not change during the execution of a
program.
✔ Basic types of C constants are shown in the flowchart
Constants
Numeric Character
Constants Constants
Single
Integer Real character String
Constants Constants constants constants
Integer Constants
• It refers to a sequence of digits.
• There are three types :-
(1) Decimal integer 0-9
(2) Octal integer 0-7
(3) Hexadecimal Integer 0-9,A to F
(1) Decimal integers consist of a set of digits 0 through 9
preceded by an optional - Or + sign.
Eg. 1234, -897, 0 ,45678, +89
Embedded spaces, commas, and non digit
characters are not permitted between digits.
Eg. 18 750 25,000 $2000
18750 25000 2000
(2) An octal integer constant consist of any
combination of digits from the set 0 through 7,
with a leading 0.
Eg. 036 0 0436 0553
(3) A sequence of digits preceded by 0x or 0X is
considered as hexadecimal integer. They may also
include alphabets A through F or a through f to
represent the numbers 10 through 15…
Eg. 0x2 0x9f 0Xbcd 0x
We rarely use octal and hexadecimal numbers
in
programming.
REAL CONSTANTS
• Integer number are inadequate to represent quantities
that very continuously , such as as distances, heights,
temperatures, prices and so on. Such numbers are
called real constants.
Eg. 0.0083 -0.75 435.36 +247.0
• A real number may also be expressed in exponential
notation. For example , the value 456.34 may be
written as 4.5634e-2 in exponential notation. E2
means multiply by 102
• The general format is
mantissa e exponent
• The mantissa is either a real number expressed in
decimal notation or an integer. The exponent is an
integer with an optional + or – sign. The letter e
separating the mantissa and the exponent can be
written in either lower case or upper case .
Eg 0.65e4 12e-2 1.8e+7 3.14E5
Single Character constant
• A single character constant contains a single character
enclosed within a pair of single quote marks .
Eg. ‘5’ ‘x’ ‘;’ ‘ ’ ‘’ 2+3=5
‘2’+’3’= 50+51=101
‘*’+ ‘4’=
Note that the character constant 5 is not the same as the
number 5
printf(“%d”, ’a’ );
would print the number 97, the ASCII value of the letter a.
• Since each character constant represents an integer value
it is also possible perform arithmetic operations
String Constant “ab”
• A string constant is a sequence of characters
enclosed in double quotes. The character may be
letters , numbers, special character and blank
space.Eg. “hello!” “X” “he890” “1987”
• printf(“****HELLO 12345 NSUT!!!!!”);
• Remember that a constant is not equivalent to the
single string constant . Character strings are often
used in programs to build meaningful programs.
BACKSLASH CHARACTER
• C supports some special backslash character that
are used in output function . For example ,the
symbol ‘\n’ stands for newline character
• Note that each one of them represents one
character , although they consist of two
characters.
• These characters combinations are know as escape
sequence.
VARIABLES
• A variable is a data name that may be used to store
data value. Unlike constant that remain unchanged
during the execution of a program ,a variable take
different values at different times during execution.
• A variable name can be chosen by the programmer
in a meaningful way so as to reflect its function or
nature in the program .some example
Aver_age123 counter_1
height total class_strength
Name name
• As mentioned earlier ,variable , names may consist
of letters ,digits and the underscore (_) character ,
subject to the following conditions:
1) They mustbegin with a letter . Some systems
permit underscore as the first character.
2) ANSI standard recognizes a length of 31 characters.
3) Uppercase and lowercase are significant. That is the
variable Total is not the same as total or TOTAL.
4) It should not be a Keyword.
5) White Spaces are not allowed.
Examples of Variable Names
Valid
Himanshu
_Average
Total_cost
student1
Invalid
**abc
Abc%^
int
Char
Roll no
✔The following special symbols are used in C having some special meaning
and thus, cannot be used for some other purpose.
[] () {} , ; : * … = # ()
{ () {} []
}
;
Braces{}: These opening and ending curly braces marks the start and end of
a block of code containing more than one executable statement.
Parentheses(): These special symbols are used to indicate function calls and
function parameters.
Brackets[]: Opening and closing brackets are used as array element
reference. These indicate single and multidimensional subscripts.
✔The symbols which are used to perform logical and mathematical
operations in a C program are called C operators.
✔ Operators used in C program are
Arithmetic operators +,-,*,/,%
Assignment operators =
Relational operators < ,>,<=,>=,!=,==
Logical operators , &&,||,!
Bit wise operators
Conditional operators (ternary operators)
Increment/decrement operators
Special Operators