Assignment 1: C Programming Language
Assignment 1: C Programming Language
Ansh Shivhare
0801IP221016
AB22G083
C PROGRAMMING LANGUAGE
● Introduction of C
The C-language was developed by Dennis Ritchie and Brian Kernighan in 1972 at the AT&T Bell
Laboratories as a system implementation language for the UNIX operating system. It is a
general-purpose and procedural-oriented programming language, structured and machine-
independent.
C is the widely used language. It provides many features that are given below.
1 Simple
2 Machine Independent or Portable
3 Mid-level programming language
4 Structured programming language
5 Rich Library
6 Memory Management
7 Fast Speed
8 Pointers
9 Recursion
10 Extensible
ASSIGNMENT 1
Ansh Shivhare
0801IP221016
AB22G083
● Data types in C
Data types in c refer to an extensive system used for declaring variables or functions of
different types. The type of a variable determines how much space it occupies in storage and
how the bit pattern stored is interpreted.
The types in C can be classified as follows −
Sr. No, Types & Description
1, Basic Types They are arithmetic types and are further classified into: (a) integer types and (b)
floating-point types.
2, Enumerated types They are again arithmetic types, and they are used to define variables that
can only assign certain discrete integer values throughout the program.
3, The type voids the type of specifier void indicates that no value is available.
4, Derived types They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union
types and (e) Function types.
● Keywords in c
A keyword is a reserved word. You cannot use it as a variable name, constant name, etc. There
are only 32 reserved words (keywords) in the C language.
A list of 32 keywords in the c language is given below:
● Variables in C
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords), for example:
1 int - stores integers (whole numbers), without decimals, such as 123 or -123
2 float - stores floating point numbers, with decimals, such as 19.99 or -19.99
3 char - stores single characters, such as ‘a’ or 'B'. Char values are surrounded by single quotes
The compilation is the process of converting the source code of the C language into machine
code. As C is a mid-level language, it needs a compiler to convert it into an executable code so
that the program can be run on our machine. This C Tutorial explains Steps Involved in
Compiling a C Program on Linux System.
1. Preprocessing
During compilation of a C program the compilation is started off with preprocessing the
#directives (e.g., #include and #define). The preprocessor (cpp – c preprocessor) is a separate
program, but it is invoked automatically by the compiler. For example, the #include command
in line 1 of helloworld.c tells the preprocessor to insert the contents of the system library
header file stdio.h directly into the program text at its place. The result is another file typically
with .i suffix. In practice, the preprocessed file is not saved to disk unless the -save-temps
option is used.
2. Compilation
In this phase compilation proper takes place. The compiler (ccl) translates helloworld.i into
helloworld.s. File helloworld.s contains assembly code. You can explicitly tell gcc to translate
helloworld.i to helloworld.s by executing the following command.
3. Assembly
ASSIGNMENT 1
Ansh Shivhare
0801IP221016
AB22G083
Here, the assembler (as) translates helloworld.s into machine language instructions, and
generates an object file helloworld.o. You can invoke the assembler at your own by executing
the following command.
4. Linking
This is the final stage in compilation of "Hello World!" program. This phase links object files to
produce final executable file. An executable file requires many external resources (system
functions, C run-time libraries etc.). Regarding our "Hello World!" program you have noticed
that it calls the printf function to print the 'Hello World!' message on console. This function is
contained in a separate pre compiled object file printf.o, which must somehow be merged with
our helloworld.o file. The linker (ld) performs this task for you. Eventually, the resulting file
helloworld is produced, which is an executable. This is now ready to be loaded into memory
and executed by the system.
5. Program Translation
Source code files: These files contain high level program code which can be read and
understood by programmers. Such files carry .c extension by convention.
Header files: These types of files contain function declarations (also known as function
prototypes) and various preprocessor statements. They are used to allow source code files to
access externally-defined functions. As a convention header files have .h extension.
Object files: These files are produced as an intermediate output by the gcc compiler during
program compilation. They consist of function definitions in binary form, but they are not
executable by themselves. Object files end with .o extension by convention (on UNIX like
operating systems), although on some operating systems e.g., Windows, and MS-DOS they
often end in .obj.
Binary executables: These are produced as the output of a program called a linker. During the
process of compiling and running C program the linker links together a number of object files to
produce a binary file which can be directly executed. Binary executables have no special suffix
on UNIX like operating systems, while they generally have .exe on Windows.
Along with above four types of files, while compiling a C program you can come across .a
and .so, static and shared libraries respectively, but you would not normally deal with them
directly.
ASSIGNMENT 1
Ansh Shivhare
0801IP221016
AB22G083