Computer Fundamentals with C and Unix
(Data types)
Lecture 02: Dec. 17, 2022 Prof. K.R. Chowdhary : Professor of CS

Disclaimer: These notes have not been subjected to the usual scrutiny reserved for formal publications. They may be distributed outside this class only with the permission of the Instructor.

2.1 Introduction

Through the program we do computations on data, which may be of various types depending on the requirements of the application. For ordinary arithmetic we need integers, for real life applications there are real numbers, called float, e.g., Rs. 30.5/kg onion, and the names are represented as character strings, and individual characters are are char types. The following example demonstrates this.


Figure 2.1: Edited program: Basic data types

The above programs gives many things to learn:

2.2 Compiling and Running the Program

The program types.c we discussed above is a simple program, where statements of C are executed in sequential order and each one is executed once only. There is no loop to repeat any statement either there is any conditional statement to select a statement for execution.


Figure 2.2: Running of program: Basic data types

The data declaration part is for restricting the size and type of data that can be stored in the variables. This binds the type with the variables, hence in the future statements in the program only that type of data can be assigned to that variable, else there will be error.

The errors in the program are checked during the compiling. The source program is types.c and the compiled program is a.out. We note that size of source program is only 328 bytes, while the size of compiled and linked program a.out is 16104 bytes. The latter is far bigger, because the for every statement in the source language (C here) there ar hundred of machine language statements. Imagine, if we are asked to write a program in machine language, it will be too tedious and time consuming process. So, let us thank to the people who wrote compilers, which have simplified the job for us, cheers to them !!


Figure 2.3: Listing the files

2.3 Some file Commands

Remember that, in the informal talk, we are learning Linux1 also, but don’t be afraid, it will not be difficult. The Unix is OS for programmers, and there is lot to learn from Unix for CS.

The Unix has directory structure, i.e., tree of folders and files, with a root. Following are some commands:

Some of the common commands for file operations are:

Table 2.1: Basic file related Linux commands




$ cat hello.c

displays the contents of hello.c file


$ cp hello.c ok.c

copies first file into second


$ mv hello.c ok.c

renames the first as second file


$ more hello.c

displays hello.c page wise


$ head hello.c

displays top 10 lines of hello.c


$ tail hello.c

displays last 10 lines of hello.c


$ wc hello.c

displays number of lines, words and characters in hello.c


$ rm filename

removes the file, i.e., deletes it from the storage

2.4 Other data types

There are more data types in C:


Figure 2.4: More variables declaration

Smallest size memory you can allocate is one byte, and memory is always 8, 16, 32, 64 bytes sizes and no in between, in all the modern computers.

Different types of variables consume different amount of space in memory (i.e., Random Access Memory (RAM)) of the computer.

Short: 1 byte

Character: 1 byte

int : 2 bytes

long : 4 bytes

double: 8 bytes

long double: 16 bytes

Examples of bytes are: 0000 0000, 0000 0001, ..., 1111 1111. Note that each one is of fixed length 8 bits.

Though we can do computations using hexadecimal, octal, and binary as well as print the in their formats, but there are no data types like binary, octal and hexadecimal.


Figure 2.5: Running the more variables program


Figure 2.6: Sizes of data types


Figure 2.7: Running Sizes program

2.5 Syntax and Semantics

The syntax is name of grammatical rules of writing C program statements. Like, correct syntax of a sentence is “Student is in School”, and not “School in is student”. Similarly, correct syntax are:

basic = 10000; da = 5000; hra = 5500;
pay = basic + da + hra;
printf(“%f\n”, pay);

and not

10000=basic; 5000=da; ....

Semantic is the meaning associated with a statement, say:

pay = basic + da + hra;

means pick up the data corresponding to variables basic, da, hra from the respective memory locations, bring them into cpu, do addition, and store the result in the memory location designated by variable “pay”.

The compiler performs mostly the syntax checking, while semantics is checked (mostly) during the running of the program.