Basics
Basics
Basics
Campus
Computer Programming (CS F111)
2021-22 Second semester
Lab1
Topics to be covered:
1. C Program structure and execution
2. Data Types
3. Reading input and printing output
$./exeFirstProg
or
$./a.out (if during compilation the name of the output file was not given)
Data Types in C
✔ char: The most basic data type in C. It stores a single character and requires a
single byte of memory in almost all compilers.
✔ int: It is used to store an integer value.
✔ float: It is used to store decimal numbers (numbers with floating point value) with
single precision.
✔ double: It is used to store decimal numbers (numbers with floating point value)
with double precision.
Control String:
It contains field specifications which direct the interpretation of input data. It consists
of conversion character % and type specifier. It is written in double quotes. Various
type specifiers are listed below.
For example:
int a; // variable is declared
scanf(“%d”,&a); // taking integer input into variable from
user
Writing on screen:
printf function is used to print output on console or monitor screen. It is similar to
scanf function, except it does not prefix with ampersand before the variable name.
Syntax of printf is as follows.
Exercises
1. Write a program to read a character and print the character using two format
specifiers %d and %c, and explain the output.
2. Write a program to print the minimum and maximum values of int and long int
using limits.h header file.
3. Write a program to define an integer variable and unsigned integer variable and
assign 2147483648 to both variables. Print both variables, Is there any difference
between both values? If yes, why?