Mod 2 Presentation 1
Mod 2 Presentation 1
1
Introduction to C
Like many other modern languages, C is derived from ALGOL(the first algorithmic language which use block
structure). ALGOL’s introduction in the 1960 led the way for the development of structured programming
concepts. Before C, several other programming languages were developed. For example in 1967 Martin Richards
developed a language called BCPL (Basic Combined Programming language). BCPL was basically a type-less (had
no concept of datatypes) language which facilitated the user with direct access of memory. This made it useful for
system programmers. Then in 1970, Ken Thompson developed a language called B. B was used to develop the
3
Low level language
Low level languages are machine level and assembly level language.
In machine level language computer only understand digital numbers i.e. in the form of 0 and 1. So, instruction
given to the computer is in the form binary digit, which is difficult to implement instruction in binary code. This type
of program is not portable, difficult to maintain and error prone.
The assembly language is on other hand modified version of machine level language. Where instructions are given
in English like word as ADD, SUM, MOV etc. It is easy to write and understand but not understand by the machine.
So, the translator used here is assembler to translate into machine level.
4
These languages have been designed to give a better machine efficiency i:e faster program execution.
High level language: These languages are machine independent, means it is portable. The language in this category is Pascal,
Cobol, Fortran etc. High level languages are understood by the machine. So, it needs to translate by the translator into machine
level.
These languages have been designed to give better programming efficiency i:e faster program development.
A translator is software which is used to translate high level language as well as low level language into machine level language.
a) Compiler
b) Interpreter
c) Assembler
5
Compiler and interpreter are used to convert the high-level language into machine level language. The program
written in high level language is known as source program and the corresponding machine level language program
Both compiler and interpreter perform the same task but there working is different. Compiler read the program at-
a-time and searches the error and lists them. If the program is error free, then it is converted into object program.
When program size is large then compiler is preferred. Whereas interpreter read only one line of the source code
and convert it to object code. If it checks error, statement by statement and hence of take more time.
6
Assembler: Translate assembly language program into machine code.
C is called middle-level language because it actually binds the gap between a machine level language and high-level
languages. A user can use C language to do System Programming (for writing operating system) as well as Application
Programming (for generating menu driven customer billing system). That's why it is called the middle-level language.
Integrated Development Environments (IDE) The process of editing, compiling, running, and debugging programs is often
managed by a single integrated application known as an Integrated Development Environment, or IDE for short. An IDE is a
windows-based program that allows us to easily manage large software programs, edit files in windows, and compile, link,
run, and debug programs.
7
Structure of C Language program
Any C program consist of one or more distinct units called functions, these functions consist of valid
C statements and are linked together through “function calls”.
a) Comment line
b) Pre-processor directive
c) Global variable declaration
a) main function ()
{
Local Variables;
Statements;
}
User defined function
{
8
}
Preprocessor Directive:
#include<stdio.h> tells the compiler to include information about the standard input/output library. The stdio.h (standard
input output header file) contains definition &declaration of system defined function such as printf( ), scanf( ), pow( ) etc.
Generally printf() function used to display and scanf() function used to read value.
Global Declaration:
This is the section where variable is declared globally so that it can be access by all the functions used in the program. And it
is generally declared outside the function.
9
main()
It is the user defined function and every function has one main() function from where actually program is started and it is
encloses within the pair of curly braces. The main( ) function can be anywhere in the program but in general practice it is
placed in the first position.
Syntax :
main()
{ ……..
…….. }
The main( ) function return value when it declared by data type as
int main( )
{
return 0;
10
}
The main function does not return any value when declared by void (means null / empty) as
Output: C language
11
The program execution start with opening braces and end with closing brace, and in between the two braces declaration
part as well as executable part is mentioned. And at the end of each line, the semi-colon is given which indicates statement
termination.
#include <stdio.h>
int main ()
{
d) Output Alt + F5
13
// Program to add two numbers
#include <stdio.h>
int main ()
{ int p1, p2, sum; //p1,p2,sum are variables and int is data type declared
p1 = 1;
p2 = 2;
sum = p1 + p2;
return 0;
}