[go: up one dir, main page]

0% found this document useful (0 votes)
7 views15 pages

Mod 2 Presentation 1

The document provides an introduction to the C programming language, detailing its history, types of programming languages, and the role of translators like compilers and interpreters. It explains the structure of a C program, including the main function, preprocessor directives, and variable declarations. Additionally, it outlines the steps for compiling and executing C programs with examples.

Uploaded by

pallavirajveer91
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)
7 views15 pages

Mod 2 Presentation 1

The document provides an introduction to the C programming language, detailing its history, types of programming languages, and the role of translators like compilers and interpreters. It explains the structure of a C program, including the main function, preprocessor directives, and variable declarations. Additionally, it outlines the steps for compiling and executing C programs with examples.

Uploaded by

pallavirajveer91
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/ 15

Introduction to Computer and Programming in C

Course Code: ES202


MODULE – II
Dr. Sheenu Rizvi
Asstt. Professor
Dept Of CSE/IT ASET
AUUP Lucknow

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

first version of UNIX.


2
C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was
designed and written by a man named Dennis Ritchie. In the late seventies C began to replace
the more familiar languages of that time like ALGOL,BPCL and B etc.

So, for as programming language concern these are of two types.

1) Low level language 2) High level language

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.

Three types of translator are there:

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

is called as object 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

void main(void ) or void main()


{
printf (“C language”);
}

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.

/*First c program with return statement*/

#include <stdio.h>
int main ()
{

printf ("welcome to c”);


return 0;
}
Output: welcome to c 12
Steps for Compiling and executing the Programs

a) Save with filename.c

b) Compile alt + F9 // if error it show error at bottom

c) Run ctrl +F9

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;

printf ("The sum of %d and %d is= %d\n", p1, p2, sum);

return 0;
}

Output: The sum of 1 and 2 is=3


14
15

You might also like