0% found this document useful (0 votes)
70 views

C Programming: DR Nazneen Akhter

This document provides an overview of the C programming language. It discusses that C is a general-purpose structured programming language that resembles Pascal and Fortran-77. The document then covers the history of C, describing its origins from languages like ALGOL, BCPL, and B. It also discusses some key features of C like its portability, use for both application and system programming, and small number of keywords. The document concludes by examining data types, operators, control structures, and functions in C.

Uploaded by

naaz_pinu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

C Programming: DR Nazneen Akhter

This document provides an overview of the C programming language. It discusses that C is a general-purpose structured programming language that resembles Pascal and Fortran-77. The document then covers the history of C, describing its origins from languages like ALGOL, BCPL, and B. It also discusses some key features of C like its portability, use for both application and system programming, and small number of keywords. The document concludes by examining data types, operators, control structures, and functions in C.

Uploaded by

naaz_pinu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

C PROGRAMMING

Dr Nazneen Akhter
Introduction

 C is a general-purpose structured programming language.


 It resembles other high-level structured programming languages such as Pascal and Fortan-77
 It also contains additional features which allow it to be used at a lower level
 C can be used for applications programming as well as systems programming
 There are only 32 keywords and its length lies in its built-in functions
 C is highly portable, since it relegated much computer-dependent features to its library functions
History
 The root of all languages is ALGOL (introduced in 1960s)
 ALGOL uses a structure programming and was popular in Europe
 In 1967 Martin Richards develop a language called BCPL(Basic Combine
Programming Language)
 Primarily BCPL was developed for system software
 In 1970, Ken Thompson created a new language called “B”
 B is created for Unix OS at Bell Laborites
 C was offspring of ALGOL, BCPL and B
 C was developed by Dennis Ritchie and was implemented at Bell Laborites in
1972
 It was developed along with the UNIIX OS and was strongly integrated with it
 In 1983, American National Standards Institute (ANSI) appointed a technical
committee to define a standard for C. the committee approved aversion of C in
December 1989 which is now known as ANSI C
 In 1999 International Standards Organization (ISO) has approved C and this
version of C is referred to as C99
Features

■ Mainly C Language is used for Develop Desktop application


and system software. Some applications of C language are
given below.
1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion
10. Extensible
Applications
Applications
■ Mainly C Language is used for Develop Desktop application and system software. Some application of C language are given below:
1. C programming language can be used to design the system software like operating system and Compiler.
2. To develop application software like database and spread sheets.
3. For Develop Graphical related application like computer and mobile games.
4. To evaluate any kind of mathematical equation use c language.
5. C programming language can be used to design the compilers.
6. UNIX Kernal is completely developed in C Language.

7. For Creating Compilers of different Languages which can take input from other language and convert it into lower level machine dependent
language.
8. C programming language can be used to design Operating System.
9. C programming language can be used to design Network Devices.
10. To design GUI Applications. Adobe Photoshop, one of the most popularly used photo editors since olden times, was created with the help of C.
11. Systems that require fast and direct access to hardware
12. Systems with limited resources (like memory)
13. Systems where performance is the most important attribute
14. Some examples are BIOS, Operating Systems, Embedded Systems, Real-time systems
Structure of a Program.

• A C program is a collection of functions.


• A function is a group of statements designed to perform a specific task.
• In C, execution starts at the main() function.
• A C program may contain one or more sections as shown below:

Document Section
It consists of comment lines giving name of the program and other details which the
program would like to letter.
 
Link Section
It provides instructions to the compiler to link functions from the system library.
 
Definition Section
It defines all symbolic constants.
 
Global Declaration Section
If a variable has to be used in more than one function then that variable will be defined as
a ‘global variable’ in this section.
Structure of a Program.

main() Function Section General structure of a C Program:


■ Every C program must have one main()
■ The execution of a C program starts with the main()
/*This is my First
■ This section contains two parts: declaration and
program*/
executable
#include <stdio.h>
■ The declaration part declares the variables
■ The executable part has at least one executable statement void main()
■ This two parts must appear between opening and closing
{
braces {…..}
■ The closing brace of the main() is the logical end of the printf(“This my first C
program prog“);
Subprogram Section
}
It contains all the user defined function and are placed
immediately after the main()
Compilation and Execution of a program

■ Executing a program in C involve a series of steps. These are:

1. Creating the program


2. Compiling the program
3. Linking the program with function that are needed from C
library; and
4. Executing the program

■ The compilation ad execution process of C can be divided in


multiple steps:

■ 1] Preprocessing:

• Using a preprocessor program to connect a C source code in


expanded source code
• “#include” and “#defines” statements will be processed and
replaced by actual source code in this step
Compilation and Execution of a program

■ 2] Compilation:

• Using a compiler program to convert expanded source code to assembly source code

■ 3] Assemble:

• Using an assembler program to convert assembly source code to object code.

■ 4] Linking:

• Using a linker program to convert object code to executable code


• Multiple units of object codes are linked together in this step

■ 5] Loading:

• Using a loader program to load the executable code into CPU for execution
Character set
Letters
 The character that can be used to form words, numbers and
expressions depend upon the computer’s programming language. Uppercase A….Z

 A subset of characters is available that can be used on most Lowercase a…..z


personal, micro, mini and mainframe computers.
 The character in C are grouped into the following categories:
Digits
1. Letters
2. Digits All decimal digits 0…..9

3. Special characters
4. White spaces White Spaces

 The compiler ignores white spaces unless they are a part of a string Black space
constant. Horizontal tab

 They are used to separate words. Carriage return


New line
 They are prohibited between the characters of keywords and
Form feed
identifiers.
Character set

Special Characters  
, comma & ampersand
. period ^ caret
: semicolon * asterisk
? question mark - minus sign
‘ apostrophe + plus sign
“ quotation mark < less than sign
! exclamation mark > greater than sign
| vertical bar ( left parenthesis
/ slash ) right parenthesis
\ backslash [ left bracket
~ tilde ] right bracket
_ underscore { left brace
$ dollar sign } right brace
% percent sign  
# number sign  
auto double int struct
Keywords
break else long switch
 Every C is classified as either a
keyword or an identifier. case enum register typedef
 Keywords serves as a basic building
blocks for program statement.
char extern return union
 All keywords have fixed meanings
and their meanings cannot be const float short unsigned
changed.
 All keywords must be written in
continue for signed void
lowercase.

default goto sizeof volatile

do if static while
Identifier

1 First character must be an


 Identifiers refer to the ‘names’ of variables, alphabet or an underscore
functions and arrays.
 These are user defined names and consists of
sequence of letters ad digits, with a letter as a
2 Must consists of only letters,
first character.
digits or underscore

 Both uppercase and lowercase are permitted,


although lowercase letters are commonly 3 Only first 31 characters are
used. signified
4 Cannot use a keyword
 The underscore is also permitted.
5 Cannot use white spaces
Data types

■ C language is rich in its datatypes

■ The variety of datatype available allow the programmer to select the type
appropriate to the needs of the application as well as the machine

■ ANSI C supports three types of datatypes: Primary, Derived and User-


defined

 char: The most basic data type in C. It stores a single character and requires a
single byte of memory in almost all compilers.

■  

 int: As the name suggests, an int variable is used to store an integer.

■  

 float: It is used to store decimal numbers (numbers with floating point value)
with single precision.

■  

 double: It is used to store decimal numbers (numbers with floating point


value) with double precision. 
Constants

■ Constants in C refer to fixed value that do not change


during the execution of program.

Integer constant
• An integer constant refers to a sequence of digits
• There are three types of integers, namely, decimal, octal and
hexadecimal
• e.g. 123, 78
• Decimal integer consists of a set of digits, 0 through 9, preceded by an
optional + or – sign
• Embedded space, commas and non-digit characters are not permitted
between digits
• An octal integer constant consists of any combination of digits from the
set 0 through 7 with a leading 0
• The sequence of digits preceded by a 0x or a 0X is considered as
hexadecimal integers. They may also include alphabets A through F
or a through f. the letters A through F represents numbers 10 to 15
Constants
Real constant
Constant Meanings

• Integer numbers are inadequate to represent quantities that vary continuously, such as \a Audible alert (bell)
distances, heights, temperatures, prices and so on.
\b Back space
• These quantities are represented by fractional parts like 228.35

\f Form feed
These are called real constants
• e.g. 123.78, 487.908 \n New line
Single character constant \r Carriage return
• A single character constant simply contains a single character enclosed within a pairs of single
quote marks \t Horizontal tab
• e.g. ‘s’, ‘7’ \v Vertical tab
String constant
\’ Single quote
• It is a sequence of characters enclosed in double quotes
\” Double quote
• The characters may be letters, numbers, special characters and blank spaces

\? Question mark
e.g. “Hello World..!!!”
Backslash character constants \\ Backslash
• C supports some special backslash character constants that are used in output functions \0 Null
• These are called as escape sequences
Variables

• It is a data name that can be used to store data value


• Unlike constants, a variable may take different values in memory
during execution
• Variables names follow the naming convention for identifiers
• For constructing variables, the rules are:
o A variable name in any combination off (1,2,3) digits, alphabets,
digital or underscore symbol
o First character in variable name must be an alphabet or an
underscore
o No comma and blanks are allowed in variable name
o No special symbol other than underscore can be used in a variable
name
o Variable name should not be a key
o Both uppercase and lowercase are significant

You might also like