0% found this document useful (0 votes)
16 views

Basic C Concepts

ASCII characters, Data types, etc.,

Uploaded by

raviataitcse
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Basic C Concepts

ASCII characters, Data types, etc.,

Uploaded by

raviataitcse
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ASCII Character Set

 ASCII (American Standard Code for Information Interchange) is a


standard character encoding used in telecommunication.
 The ASCII pronounced ‘ask-ee’, is strictly a seven bit code based on
English alphabet. ASCII codes are used to represent alphanumeric data.
 The code was first published as a standard in 1967.
 It was subsequently updated and published as ANSI X3.4-1968, then as
ANSI X3.4-1977 and finally as ANSI X3.4-1986. Since it is a seven bit
code , it can at the most represent 128 characters.
 It currently defines 95 printable characters including 26 upper case
letters (A to Z) , 26 lower case letters , 10 numerals (0 to 9) and 33
special characters including mathematical symbols, punctuation marks
and space character.

Code Character Code Character Code Character Code Character


0 • 32 [space] 64 @ 96 `
1 • 33 ! 65 A 97 a
2 • 34 " 66 B 98 b
3 • 35 # 67 C 99 c
4 • 36 $ 68 D 100 d
5 • 37 % 69 E 101 e
6 • 38 & 70 F 102 f
7 • 39 ' 71 G 103 g
8 ** 40 ( 72 H 104 h
9 ** 41 ) 73 I 105 i
10 ** 42 * 74 J 106 j
11 • 43 + 75 K 107 k
12 • 44 , 76 L 108 l
13 ** 45 - 77 M 109 m
14 • 46 . 78 N 110 n
15 • 47 / 79 O 111 o
16 • 48 0 80 P 112 p
17 • 49 1 81 Q 113 q
18 • 50 2 82 R 114 r
19 • 51 3 83 S 115 s
Code Character Code Character Code Character Code Character
20 • 52 4 84 T 116 t

21 • 53 5 85 U 117 u

22 • 54 6 86 V 118 v

23 • 55 7 87 W 119 w

24 • 56 8 88 X 120 x

25 • 57 9 89 Y 121 y

26 • 58 : 90 Z 122 z

27 • 59 ; 91 [ 123 {

28 • 60 < 92 \ 124 |

29 • 61 = 93 ] 125 }

30 • 62 > 94 ^ 126 ~

31 • 63 ? 95 _ 127 •

Keywords in C
Detailed list of Data Types in C

Formatting Input/Output

The printf (print formatting) in C

The printf function is used to display information required by the user and also
prints the values of the variables.

Syntax: printf(“contrl string”, variable list);

Prototype of control string can be as follows:


 Each control string must begin with a % symbol.
 The % character/symbol specifies how the variable in the list of variables
has to be printed.

Flags:

Flags specify output justification such as decimal point, numerical sign, trailing
zeros, or octal, decimal, or hexadecimal prefixes.

Width:

Width specifies the minimum number of characters to print, that is, the
minimum number of positions in the output.

Precision:

 Precision specifies the maximum number of characters to print.


 For integer specifiers (d,i,o,u,x,X): precision specifies the minimum
number of digits to be written.
 For floating point numbers, the precision specifies the number of decimal
places to be printed.
 For example, %7.3f means print a floating point value of maximum 7
digits where 3 digits are allotted for the digits after decimal point.
 For character strings, precision specifies the maximum number of
characters to be printed.

Length:

Length field is used when short int, long int and long double data types used.

Specifier:

Specifier is used to describe the type and interpretation of the value of the
variable in the variable list.
Example:1

Example:2
The scanf() in C

The function scanf() stands for scan formatting and used to read formatted data
from the keyboard.

This function takes a text stream from the keyboard, extract and formats data
from the stream according to a format control string and then stores the data in
the specified variables.

Syntax: scanf(“control strin”, arg1, arg2,arg3,…...argn);

The control string specifies the type and format of the data that has to be
obtained from the keyboard and stored in the memory locations pointed by the
arguments arg1,arg2,arg3,….argn.

The arguments are actually the variable address where each piece of data are to
be stored in memory.

Arguments arg1,arg2,arg3….argn should prefix with & symbol.

Examples:

To read integer numbers: scanf(“%d%d”,&number1,&number2) // Valid

Scanf(“%d”,&number1,&number2); // Invalid

Scanf(“%d%d%d”,&number1,&number2);// Invalid

To read floating point number: scanf(“%f”,&number);

To read character: scanf(“%c”, &ch);

The scanf function can be used to read variables of different types in one single
statement.

Example: int num;

Float fnum;

Char ch;

scanf(“%d%f%c”,&num,&fnum,&ch);

You might also like