0% found this document useful (0 votes)
27 views6 pages

C Unit1 PartA

Uploaded by

Pushpa Prashanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

C Unit1 PartA

Uploaded by

Pushpa Prashanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit-1 Part-A

Overview of C Language

C is a general-purpose high-level language developed by Dennis Ritchie in 1972 at Bell


Laboratories. In 1988, the language was formalised by American National Standard
Institute (ANSI). In 1990, a version of C language was approved by the International
Standard Organisation (ISO). In 1989, the C language was standardized, where C language
features were defined, and that version of C is also referred to as C89.c programming language
that was developed to do system programming for the operating system UNIX, but later it was
used for developing software and programs for daily usage. It is still being used to develop
operating systems and for creating system-level programs, by big tech companies

Facts about C
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around 1970
• The language was formalized in 1988 by the American National Standard Institue (ANSI).
• By 1973 UNIX OS almost totally written in C.
• Today C is the most widely used System Programming Language.

History of C language

C language has evolved from three different structured languages ALGOL, BCPL, and B
Language. It uses many concepts from these languages while introduced many new concepts
such as datatypes, struct, pointer, etc.

BCPL was developed by Martin Richards, based on which the B language was created
by Ken Thompson. And then the B language was the language using which the C language
was created.

In 1989, the language was formalized by American National Standard Institute(ANSI).

In 1990, a version of the C language was approved by the International Standard


Organisation(ISO), and that version of C is also referred to as C89.

After the C language was accepted worldwide and programmers around the world started using
it, soon, to improve C language further, the work on the development of C++ language started.

The idea behind creating C language was to create an easy language that requires a simple
compiler (to translate the code from English to binary (0's and 1's that computer understands))
and to enable programmers to write complex programs in a language which is close to
English because earlier programmers had to write Machine instructions which were very
difficult to remember.
C language compiler converts the readable C language code into machine instructions.

Why is C Language so popular?


C language is a very good language to introduce ourself to the programming world, as it is a
simple, and easy-to-learn language that is capable of doing wonders.

Programs that are written in C language take very little time to execute and almost execute at
the speed of assembly language instructions. (Assembly level instructions are nothing but
direct commands to communicate with computer's hardware)

Initially, C language was mainly used for writing system-level programs, like designing
Operating Systems, because in the eighties (1980-89) the fight to make a stable, worldwide
accepted operating system was going on.

But C language can be used to develop other applications as well, like Text Editors,
Compilers, Network Drivers, many traditional PoS(Point of Sale) software like Restaurant
Billing systems, etc.

Characteristics or feature of C:
▪ C is a general purpose programming language.
▪ It is a structured programming language (It allows modularization process of dividing problems
into sub-problems and C has structured statements like sequence, selection and iteration)
▪ C is a middle level language (C is a high level language but also incorporates features of low-level
languages like manipulation of bits, bytes, words and addresses.)
▪ Helps in development of system software ( C is used for writing application programs and since it
has low level languages features it can be used in development of system software)
▪ Has rich set of operators and data types and built-in functions.
▪ Provides compact representation for expressions. This makes the language simple, orderly and easy
to learn.
▪ No rigid format. Any number of statements can be typed in a single line
• Portability: any C program can be run on different machines with little or no modifications.
• Less number of reserved words.
• Pointer,C provides the feature of pointers. We can directly interact with the memory by
using the pointers. We can use pointers for memory, structures, functions, array etc.
• Ability to extend itself by adding functions to its library

• Simple, C is a simple language in the sense that it provides structured approach (to break
the problem into parts), rich set of library functions, data types etc.
• Machine Independent or Portable,Unlike assembly language, c programs can be executed
in many machines with little bit or no change. But it is not platform-independent.
• Case sensitive Language-In C, the uppercase and lowercase characters are different. That
means if is not the same as IF in C language.

Basic structure of a C program or Syntax:


Every C program includes the following components

1.Documentation section: The documentation section consists of a set of comment lines


giving the name of the program, the author and other details, which the programmer would like
to use later.
2.Pre-processor directives or Link section: these statements begin with # symbol. They direct
the C pre-processor to include header files and symbolic constants into a C program.
E.g #include<stdio.h> : For the standard input, output function
#include<conio.h> : For the Console input, output function
3.Definition section: The definition section defines all symbolic constants such using the
#define directive.
E.g #define NULL 0 : For defining symbolic constant, NULL=0
#define PI 3.14 : For defining symbolic constant PI =3.14
4.Global declaration section: There are some variables that are used in more than one
function. Such variables are called global variables and are declared in the global declaration
section that is outside of all the functions. This section also declares all the user-defined
functions
5.main () function section: This is the main function of every C program. Execution of a C
program starts with Main (). No C program is executed without the main () function. It should
be written in lowercase letters and should not be terminated with semicolon. It calls other
library functions and user defined functions. There must be one and only one main () function
in any C program.
A pair of flower brackets{ }: The flower brackets indicate body of the program, which
includes instructions to perform the required task. { indicates beginning of the main ()
function and } indicates end of the main() function.
Declarations: It is the part where all the variables, arrays, functions etc., used in the C
program are declared and may be initialized with their basic data types.
Statements: These are instructions to perform certain operations like input, output,
assignment, arithmetic statements, control statements and other statements. They also
include comments. Comments are explanatory notes on some instructions. The statements
to be commented must be enclosed within /* and */. The comment lines are not compiled
and executed.
6. Subprogram section: If the program is a multi-function program, then the subprogram
section contains all the user-defined functions that are called in the main () function. User-
defined functions are generally placed immediately after the main () function, although they
may appear in any order.
Example of c program:
Compilation process in c

The C Compilation Model the compilation is a process of converting the source code into
object code. It is done with the help of the compiler. The compiler checks the source code for
the syntactical or structural errors, and if the source code is error-free, then it generates the
object code.

The c compilation process converts the source code taken as input into the object code or
machine code. The compilation process can be divided into four steps, i.e., Pre-processing,
Compiling, Assembling, and Linking. C source files are typically named with .c extension.

The Preprocessor accepts source code as input and is responsible for


• removing comments
• Interpreting special preprocessor directives denoted by #.
For example
#include -- includes contents of a named file. Files usually called header files.
#include<math.h> -- standard library maths file.
#include<stdio.h> -- standard library I/O file
#define -- defines a symbolic name or constant. Macro substitution.
#define MAX_ARRAY_SIZE 100
The C Compiler translates source to assembly code. The source code is received from the
preprocessor.
The assembler creates object code. On a UNIX system you may see files with a .o suffix (.OBJ
on MSDOS) to indicate object code files.
Link Editor If a source file references library functions or functions defined in other source
files the link editor combines these functions (with main()) to create an executable file.

o Firstly, the input file, i.e., hello.c, is


passed to the preprocessor, and the
preprocessor converts the source code into
expanded source code. The extension of the
expanded source code would be hello.i.
o The expanded source code is passed to the
compiler, and the compiler converts this
expanded source code into assembly code. The
extension of the assembly code would
be hello.s.
o This assembly code is then sent to the
assembler, which converts the assembly code
into object code.
o After the creation of an object code, the
linker creates the executable file. The loader
will then load the executable file for the
execution.

You might also like