Computer Programming (CS F111)
LAB - 2
Topics to be covered: Keywords, Primary Data Types, Constants, Variables, Basic Arithmetic
Expressions, Number system
Lab notes
Keywords
Keywords are the reserved words. They have fixed meanings and these meanings cannot be
changed. They must be written in lowercase.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Primary Data Types
Type Min size (in bits) Format Specifier
char 8 %c
signed char 8 %c
unsigned char 8 %c
short int 16 %hd (decimal), %ho (octal), %hx (hex)
signed short int 16 %hd (decimal), %ho (octal), %hx (hex)
unsigned short int 16 %hu (decimal), %ho (octal), %hx (hex)
int 16 %d (decimal), %o (octal), %x (hex)
signed int 16 %d (decimal), %o (octal), %x (hex)
unsigned int 16 %u (decimal), %o (octal), %x (hex)
long/long int 32 %ld (decimal), %lo (octal), %lx (hex)
signed long int 32 %ld (decimal), %lo (octal), %lx (hex)
unsigned long int 32 %lu (decimal), %lo (octal), %lx (hex)
float 32 %f or %g or %e or %a
double 64 %f or %g or %e or %a
long double 128 %Lf or %Lg or %Le or %La
1
, Constants
The constants refer to fixed values that the program may not alter during its execution. These
fixed values are also called literals.
Integer
constants
Numeric
constants
Real constants
Constants
Single
character
Character constants
constants
String
constants
• Integer constants: There are three types of integers: decimal, octal, and hexadecimal.
- Decimal integers consist of a set of digits, 0-9, preceded by unary + or -.
Ex: 100, -101, +102
- Octal integers are always preceded by 0. It consists of a combination of digits 0-7.
Ex: 0144, -0145, 0146
- Hexadecimal integers are preceded by 0x or 0X. It consists of a combination of
digits 0-9 and A to F or a to f.
Ex: 0x64, -0X65, 0X66
- Unsigned integers, unsigned long integers, and long integers can be expressed with
suffix u, ul, l or U, UL, L respectively.
Ex: 2022u or 2022U, 2022ul or 2022UL, 2022l or 2022L
• Real constants: Real constants are having a whole number followed by a decimal point
and fractional part. It is possible to omit digits before or after decimal point.
Ex: 2.022, -20.22, .22, -20.
A real constant can be expressed in exponential notation.
Ex: 20.22e2, 2.022E3, 20220e-1
• Single character constants: A single character constant contains a single character
enclosed within a pair of single quote marks.
Ex- '2', 'A', 'a', ';'
• String constants: A string constant is a sequence of characters enclosed in double
quotes. The characters may be letters, numbers, special characters, and blank space.
Ex- "Hello!!!", "2022", "Hello 2022!", "5+5"
2