btech i pic u-1 introduction to c language

33
Course: BTECH Subject: Programming In C Language Unit-1 Introduction to C language

Upload: rai-university

Post on 16-Jul-2015

75 views

Category:

Education


1 download

TRANSCRIPT

Course: BTECH

Subject: Programming In C Language

Unit-1

Introduction to C language

Function OF Computer

Input -- Input devices enable us to get information into a computer. Someexamples include a keyboard, mouse, microphone, scanner, or digital camera.

Storage -- There are two types of storage: temporary and long-term.RAM, or random access memory, is temporary, meaning it stores information asyou use it, but it is being constantly erased and rewritten as you open and closefiles.Long-term storage holds information for as long as you want it. Hard drives,portable hard drives, floppy drives, flash drives, CD’s, and DVD’s are long termstorage devices.

Processor -- A microprocessor controls the computers’ functions. It is smallerthan a dime, but contains millions of transistors that perform millions ofinstructions per second. The microprocessor performs these instructions using athree-step process: fetch, decode and execute.

Output -- Information that has been processed is communicated back to theuser in the form of words, sounds or pictures, and is delivered through printers,speakers, monitors or other output devices. Sometimes output is just writtenback to a storage dev

Basic Building Block Of Computer

Control Unit-

this is the device or a part of computer responsible orperforms such regulating functions..

Arithmetic Logic Unit- this is the part or a circuitry ofthe Microprocessor chip for arithmetic operations,proportional and related functions, and logicalfunctions.

Memory- this is a part of computer or a card or modulesthat inserted to the motherboard’s slot

Input -The System Unit that the system of computerfeeds or decode first the data before to display using theoutput devices of computer.

Output Devices- this is refer to the devices ofcomputer that have an ability to display the informationor can produce a hardcopy of a document.

Computer Applications

Classification Of Computer

Classification Of Programming Language

What is UNIX?

UNIX is an operating system which was first developed inthe 1960s, and has been under constant development eversince. By operating system, we mean the suite of programswhich make the computer work. It is a stable, multi-user,multi-tasking system for servers, desktops and laptops.

UNIX systems also have a graphical user interface (GUI)similar to Microsoft Windows which provides an easy touse environment.

However, knowledge of UNIX is required for operationswhich aren't covered by a graphical program, or for whenthere is no windows interface available, for example, in atelnet session.

Cont..

There are many different versions of UNIX, althoughthey share common similarities. The most popularvarieties of UNIX are Sun Solaris, GNU/Linux, andMacOS X.

What is LINUX?

It is the software on a computer that enables applicationsand the computer operator to access the devices on thecomputer to perform desired functions.

Linux is developed collaboratively, meaning no onecompany is solely responsible for its development orongoing support. Companies participating in the Linuxeconomy share research and development costs withtheir partners and competitors

Windows

The operating system gives the framework upon which allother services and applications run. The majority of homeusers use a Windows based machine. Most of today’sapplications and games are designed to run solely onMicrosoft systems.

Microsoft Windows is extremely popular in schools andcolleges, many businesses also use Windows.

The oldest of all Microsoft’s operating systems is MS-DOS (Microsoft Disk Operating System). MS-DOS is a text-based operating system. Users have to type commands rather than use the more friendly graphical user interfaces (GUI’s)available today

What is algorithm?

A method that can be used by a computer for the solutionof a problem.

A sequence of computational steps that transform theinput into the output.

The word ”algorithm” comes from the name of a Persianauthor, Abu Ja’far Mohammed ibn Musa al Khowarizmi (c.825 A.D.), who wrote a textbook on mathematics.

An algorithm (pronounced AL-go-rith-um) is a procedureor formula for solving a problem.

Algorithm

Write an algorithm and draw the flowchart for finding the average of two numbers Algorithm:

Input: two numbers x and y

Output: the average of x and y

Steps:

input x

input y

sum = x + y

average = sum /2

output average

Introduction to flowcharts

A flowchart is a graphical representation of an algorithm.

• Start or end of the program

• Computational steps or processing function of a program

• Input or output operation

• Decision making and branching

• Connector or joining of two parts of program

Introduction of ‘C’

Root of the morden language is ALGOL 1960. It’s first computerlanguage to use a block structure.

It gave concept of structured programming.

In 1967, Martin Richards developed a language, BCPL (BasicCombined Programming Language)

In 1970,by Ken Thompson created a language called as ‘B’.

It used to create early version of Unix.

In 1972,by Dennis Ritchie introduced new language called as ‘C’ .

1972 Traditional C Dennis Ritchie

1990 ANSI/ISO C ISO Committee

1978 K&R C Kernighan &Ritchie

1989 ANSI C ANSI Committee

Features Of C

It is robust lang whose rich setup of built in functions and operator can be used to write anycomplex prog

Prog written in c are efficient due to severals variety of data types and powerful operators. The c complier combines the capabilities of an assembly lang with the feature of high level

language. Therefore it is well suited for writing both system software and business package.

There r only 32 keywords, severals standard functions r available which can be used fordeveloping prog.

c is portable lang , this means that c programes written for one computer system can be run onanother system, with little or no modification.

c lang is well suited for stuctured programming, this requires user to think of a problems interms of function or modules or block. A collection of these modules make a programdebugging and testing easier.

c language has its ability to extend itself. A c program is basically a collection of functions that aresupported by the c library. We can contuniously add our own functions to the library with theavaibility of the large number of functions.

In india and abroad mostly people use c programming lang becoz it is easy to learn andunderstand

Basic structure of C programming

To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are illustrated below.

Documentation section

Link section

Definition section

Global declaration section

main () Function section

{

Declaration part

Executable part

}

Subprogram section

Function 1

Function 2

…………..

…………..

Function n (User defined functions)

Basic structure of ‘C’

Documentation Section It has set of comment lines(name of program, author details).

What is Comment line?? To guide a programmer to write a note for function,operation,logic in

between a program.

Non-executable statement.

Can’t be nested.

e.g:- /* Hello /* abc */ Hi */

ERROR.

Link Section

It provides instructions to the compiler to link function fromthe system library.

# include Directive:-

To access the functions which are stored in the library, it isnecessary to tell the compiler , about the file to be accessed.

Syntax:-

#include<stdio.h>

stdio.h is header file.

Definition Section

defines all symbolic constants.

#define instruction defines value to a symbolic constant.

#define:-

It is a preprocessor compiler directive, not a statement.

Therefore it should not end with a semicolon.

Generally written in uppercase.

Global Declaration Section

Some variables that are used in more than on function,

such variables (global variables) declared in the globaldeclaration section.

It also declares all the user-defined function.

Every ‘C’ program must have one main() function section.

It contains two parts

1) Declaration part:

It declares all variables used in the executable part.

2) Executable part:

It has atleast one statement.

Main() function section

A simple C program: Printing a line of text

#include <stdio.h>

main()

{

printf(“hello, world\n”);

}

Program output:

hello, world

Executing a C program :

Executing a C program involves a series of steps.

They are,

Creating the program.

Compiling the program.

Linking the program with functions that are neededfrom the C library.

Executing the program.

How to run a program?

There are two ways to run programs written in a high-levellanguage.

The most common is to Compile the program

The other method is to pass the program through an interpreter.

Compiler

Why compiler is require ?

As machine (a processor) can operate On binary code instructiononly…..If we use higher level language then …For execution of theprogram we must Convert it to lower level / machine levelCode.

Means,

A program that translates Source code into object code.

The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions.

Interpreter:

which analyzes and executes each line of source codewithout looking at the entire program.

Advantage of interpreter:

It can execute a program immediately.Compilers require some time before an executable programemerges.But,However, programs produced by compilers Run much fasterthan the same programs executed by an interpreter.

Compiler

checks for syntax errors if any on success coverts ‘C source code into object code form which is nearer to machine…

process of compiling and running a C program

References:

1. Programming in C by yashwant kanitkar

2. ANSI C by E.balagurusamy- TMG publication

3. Computer programming and Utilization by sanjay shah Mahajan Publication

4. .www.cprogramming.com/books.html

5. en.wikipedia.org/wiki/C_(programming_language)

6. www.programmingsimplified.com/c-program-example

7. http://cm.bell-labs.com/cm/cs/who/dmr/chist.html

8. http://en.wikipedia.org/wiki/Comparison_of_programming_languages

9. http://en.wikipedia.org/wiki/List_of_C-based_programming_languages

10. http://en.wikipedia.org/wiki/C_(programming_language)