100% found this document useful (1 vote)
100 views

M1 C Programming

This document provides an introduction to the C programming language. It discusses the evolution of C from earlier languages like BCPL and B. C is described as a second-generation language due to its low-level features like pointers, and a third-generation language due to constructs like conditionals and loops. Key features of C discussed include pointers, dynamic memory allocation, recursion, and bit manipulation operations. Sample code is provided to illustrate basic C programs and factored code using functions.

Uploaded by

Deepak Malusare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
100 views

M1 C Programming

This document provides an introduction to the C programming language. It discusses the evolution of C from earlier languages like BCPL and B. C is described as a second-generation language due to its low-level features like pointers, and a third-generation language due to constructs like conditionals and loops. Key features of C discussed include pointers, dynamic memory allocation, recursion, and bit manipulation operations. Sample code is provided to illustrate basic C programs and factored code using functions.

Uploaded by

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

C Programming

Module 1: Introduction to C
Agenda

1 Introduction to C Programming

2 Data Types & I/O Operations

3 Conditional & Iterative constructs

4 Logical Operators & Formatted I/O

2
Introduction to C Programming

3
Objectives

In this session, you will learn to:


Describe the evolution of the C programming language
Describe C as a second-generation as well as a third-generation language

4
Evolution ???

Ken Thompson created the B


language in 1969 from Martin Martin Richard
Richard's BCPL

Dennis Ritchie of Bell


Laboratories later converted B
into C by retaining most of B's
syntax in 1972 and wrote the
first compiler.

Ken Thompson & Dennis Ritchie

5
6
A very Small history

Originally used to develop UNIX and modern operating systems

Standardized using ANSI standards in 1989, updated in 1999

Modern C compilers adhere to ANSI C standards and provide additional


features

7
Nature of the C Language

From its evolution, it was natural for C to exhibit the powerful low-level
features of second generation languages like pointers, bit manipulation etc.

It also supports conditional constructs, loop constructs, a rich list of


operators, and a variety of data types that is so typical of any third
generation language.

The combined features of second and third generation language make C a


very powerful and a flexible language.

8
Nature of the C Language (Contd.).

These features of C make it possible to use the language for systems


programming like development of compilers, interpreters, operating
systems, graphics and general utilities.

It is also ideal for a host of applications in the commercial environment.

Much of the Unix operating system has been written in the C language.

9
Block Structured Nature of C

The basic unit of code in C is written as a C function, that can in turn be


used as building blocks to write more C functions, thus facilitating modular
programming.

C provides all features of structured programming such as writing


programs as functions, functions returning values, functions defining its
own local variables etc.

C language offers only a handful of functions that form the core of the
language; rest of the functions, available as part of the language libraries, are
developed using the core functions, thus expanding the scope of the
language.

10
Block Structured Nature of C (Contd.).

This promotes functionally cohesive code and therefore, facilitates


reusability.

Thus standalone functions can be written as part of a library that can be


deployed in other applications.

11
The C Language: Features

Pointers: In addition to referencing a memory location through a variable


name, the C language allows reference to a memory location by its internal
address, or byte number called a pointer.

Memory Allocation: Generally, in most programming languages, memory


is assigned to a variable name at the time of definition. C allows dynamic
allocation of memory; i.e., a C program can request the operating system
to release memory for the use of the program at the time of execution.

12
The C Language: Features

Recursion: In C, a function can call itself. Such functions are called


recursive functions.

Bit Manipulation: C allows manipulation of data in its lowest form of


storage; i.e., it is possible to manipulate the bits within a byte using bit shift
operators (right bit shift, left bit shift operators), and the bitwise or |,
bitwise exclusive or ^, and the bitwise and & operator.

13
The C Language: Features (Contd.).

Keywords: There are only 32 keywords, i.e., reserved words that cannot
be used as a variable declaration. The C99 has introduced five additional
keywords.
(inline, restrict, _Bool, _Complex and _Imaginary).
Library Functions: C is accompanied by a number of library functions to
carry out various commonly used operations. These functions are not part
of the language, but are supplied as a part of C compiler. Features which
tend to be computer-dependent are generally written as library functions.

14
The Hello World Program

/* Comment statements */ /* The Hello World program */


Preprocessor directives # include <stdio.h>
main() main()
{ {
Program statements; printf(Hello World\n);
} }

15
Factored Code: An Example

/* Comment statements */ /* A sample C program */


Preprocessor directives # include <stdio.h>
Function prototypes; int sum();
global variable declarations; int a=10, b=20;
main() main()
{ {
local variable declarations; int c;
Program statements; c = sum();
} printf(%d+%d = %d \n,a,b,c);
}
[Additional functions .] int sum()
{
return(a+b);
}

16

You might also like