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

POP - Module-1 - Chapter 2-Structure of C Program

The document provides an overview of the C programming language. It discusses the importance of C, the history and evolution of C from earlier languages like ALGOL and BCPL, key features of C like efficiency and portability. It also describes basic C program structure with sections for documentation, preprocessor directives, global declarations, function definitions, and the main function. The main sections of a C program and basic tokens used in C like keywords, identifiers, and constants are also summarized.

Uploaded by

Vatsala B R
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
0% found this document useful (0 votes)
217 views

POP - Module-1 - Chapter 2-Structure of C Program

The document provides an overview of the C programming language. It discusses the importance of C, the history and evolution of C from earlier languages like ALGOL and BCPL, key features of C like efficiency and portability. It also describes basic C program structure with sections for documentation, preprocessor directives, global declarations, function definitions, and the main function. The main sections of a C program and basic tokens used in C like keywords, identifiers, and constants are also summarized.

Uploaded by

Vatsala B R
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/ 48

 Course Instructor

 Nandini P

1
Importance of the Subject
• ‘C is the base language of any other
programming language.
• To be a Good Programmer one must know
fundamentals of C programming language.

2
History of ‘C’

 Root of the modern language is ALGOL 1960.


 It’s first computer language to use a block structure.
 It gave concept of structured programming.
 In 1967, Martin Richards developed a language, BCPL (Basic
Combined Programming Language)

3
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’ at Bell laboratory

4
Features Of ‘C’
 It is a robust language.
General purpose high level language.
Programs written in ‘C’ are efficient and fast.
(Because of variety of data types and powerful operators)
 Highly Portable. (related to OS)
Well suited for structured programming.
Ability to extend itself.
Core language
 Documentation section
 Link Section
 Definition Section
 Global Declaration Section
 main() function section
 {
 Declaration part
 Executable part
 }
 Subprogram section
 Function1
 Function2 … ( user defined function)

6
[Comments ]
Pre-processor Directives
[Global Declarations]
[Function Declarations]
main()
{
Declaration Section
Executable Section
}
 
 
7
[Comments ]
Pre-processor Directives
[Global Declarations]
[Function Declarations]
main()
{
Declaration Section
Executable Section
}
 
 
8
• consists of a set of comment lines giving the short description explaining the
purpose of each statement or set of statements in a program.
• These comments are useful to the programmer to understand the logic of the
program but are ignored by the compiler.
• Any comment must start with two characters
• Block Line Comments /* and end with */ .
• Single line comments are //
• The symbols /* marks the beginning of the comment and */ marks the end of
the comment.
• The symbols /* and */ are called comment delimiters.
• For eg: /* first C program*/
9
• The preprocessor statements start with the symbol # symbol.
• These statements instruct the compiler to include some of the files in the
beginning of the program.
• For example,
• #include<stdio.h>
• #include<math.h> are the files that the compiler includes in the beginning of
the program. Using the preprocessor directive the user can define the constants
also.
• For example,
• #define MAX 1024
• #define PI 3.1417
• Here MAX and PI are called symbolic constants. 10
In C program execution starts from the function main which
can be written as “void main()” or “int main()”

-if void main() is used –no need of return type

-if int main() is used-need to have return type

11
• A series of statements that perform a specific action will be enclosed

within braces { and } and present immediately after the program header

is called the body of the program.

• The body of the program contains two essential parts

• Declaration section

• Execution section

12
• These are the building blocks of the program.

• They represent the instructions given to the computer to perform a

specific task.

• The instructions can be input/output statements, simple assignment

statements, control statements etc.

• Each executable statement must end with a “ ; ”.

13
14
The statement which instructs the compiler to display or print
the string, expression value or variable value to the console
device is called print statement.

print(): This function prints the data stored in specified


memory location

15
simple forms of printf () statement:

16
17
 The General form of printf is:
printf(“control strings”,arg1,arg2,arg3……..argn);

 The general form of scanf is:


scanf(“control strings”,arg1,arg2,arg3……..argn);

18
19
20
/*Documentation Section: program to find the sum of
two numbers*/
#include <stdio.h> /* Pre-processor Directives */
int result; /*global declaration section*/
main()
{
int a,b; /*declaration part*/
printf("Enter two numbers for a and b"); /*
executable part starts here*/
scanf("%d%d",&a,&b);
result= a + b;
printf("The result is=%d",result);
}

LJD, DEPT OF CSE, SJEC 21


22
 It contains source code of the program
 File extension is .c
 main() is the staring point of execution

23
 While working with large projects, need to
separate subroutine from the main()
 So option for this is make subroutine and

store them in a different file known as header


file
 Compile the source code of the subroutine

and then link to the object file in which


subroutine are required.

24
25
 They are generated by compiler after
processing source file
 Contains binary code(.obj file)
 Linker uses this object file to produce an

executable file(.exe file)

26
 Generated by linker which links various object
Files to produce executable file

27
 Create a program
 Compiling the program
 Linking the programs with functions
 Executing the program

28
29
30
 Process certain kinds of data and provide
output known as information
 Task is accomplished by executing

instructions called program


 Instructions are formed using rigid rules

called syntax rules


 C has its own vocabulary and grammar

31
 C Character set is a collection of characters supported in C
programming language.
 C Programming language has a rich set of characters which are used
to construct c program instructions.
 Alphabets
C Language supports all alphabets of English. It supports both
UPPERCASE & lowercase letters
 Digits
C Language supports 10 digits to construct numbers. Those 10 digits
are 0,1,2,3,4,5,6,7,8,9
 Special Symbols
C supports a rich set of special symbols that include symbols to
perform mathematical operations, condition checking, white space,
back space, etc…

32
 In C Programming Language, the character set
follow ASCII (American Standard Code for
Information Interchange) code text format.
 - Every character in C language has the

respective ASCII value which is used to convert


a character into Binary language.

33
34
 In a passage of text individual words and
punctuations called tokens
 In c smallest individual units are known as C

tokens
 6 types and programs written using these

tokens

35
36
Keywords :

- Every keyword is classified as either keyword or


identifiers
- All keywords have fixed meanings

- Keywords serves a building block of program


statements.
- Written in lowercase

37
38
- Identifiers refer to the names of variables, functions and arrays
- User-defined names consists of sequence of letters and digits
with letter as first character
- Allow both upper and lowercase as well as underscore
- Rules for Identifiers:-
 1. First character must be an alphabet
 2. Must consists of only letters, digits or underscore
 3. Only first 31 characters are significant
 4. Cannot use a keywords
 5. Must not contain white space

39
 Refers to fixed values that do not change
during execution of program

40
Integer constants:
Integer constant-3 types of integer
1. Decimal(0 through 9,preceded by optional –or
+ sign)
2. Octal(digits from 0 through 7 with leading 0)
3. Hexadecimal(digits preceded by 0x or 0X and
includes alphabets A through F which represent
numbers 10 through 15)

41
• Using integer numbers it is inadequate to represent
quantities like distances, heights, temperatures, prices…etc
• These quantities can be represented by numbers containing
fractional parts like 12.567,Such numbers are called real
constants
• Real numbers also represented in exponential notation by
format:0.6e4,10e-1,-1.4E-1
mantissa e exponent
• Exponent can be written in either plus or minus sign
• Letter ‘e’ separating the mantissa and exponent can either
lowercase or uppercase
• White space is not allowed

42
Single character constants
 Contains single character enclosed within a pair of

single quote marks


 Example: ’5’, ’X’

 Character constants have integer values as ASCII values

String Constants
 sequence of characters enclosed in double quotes

 Example: ”Hello”,”1986”

 Blank spaces are allowed in both constants

43
• Data name used to store a data value
• Take different values at different times during execution
• Name should be meaningful to reflect its function
• Conditions:
1. Begin with letter but some systems permit underscore as first
character
2. Recognizes a length of 31 characters but first eight characters
are significant
3. Upper and lowercase are significant
4. It should not be a keyword
5. White space is not allowed

44
45
46
47
48

You might also like