SlideShare a Scribd company logo
1
Structure of C Program
A C program basically consists of the following parts:
• Preprocessor Commands
• Functions
• Variables
• Statements & Expressions
• Comments
Structure of C Program
2
Preprocessor Commands
Main Function
Library Function
End of Program
Comment
3
Preprocessor Commands
 These commands tells the compiler to do preprocessing before doing
actual compilation.
 Like #include <stdio.h> is a preprocessor command which tells a C
compiler to include stdio.h file before going to actual compilation.
4
Functions
 Functions are main building blocks of any C Program.
 Every C Program will have one or more functions and there is one
mandatory function which is called main() function.
 The C Programming language provides a set of built-in functions.
 In the above example printf() is a C built-in function which is used to print
anything on the screen.
5
Comments
 Comments are used to give additional useful information inside a C
Program.
 All the comments will be put inside /*...*/ as given in the example above.
 A comment can span through multiple lines.
/* comment for multiple line */
// single line comment
6
Variable and Variable Declaration
• Variable is a named memory location that can hold various values.
• All variables must be declared before they can be used.
• When we declare a variable, we tell the compiler what type of
variable is being used.
• A declaration associates a group of variables with a specific data
type.
7
Structure of C Program
Preprocessor Commands
Main Function
Library Function
End of Program
Comment
8
C’s Basic Data Type
Type Keyword format
Specifier
Memory
Requirements
Character data char %c 1 Byte
Signed whole numbers int %d 2 or 4 Byte
Floating-point numbers float %f 4 Byte
Double-precision floating-
point number
double %lf 8 Byte
valueless void ---
9
How to Declare Variables
•To declare a variable, use this general form:
type var-name;
•In C, a variable declaration is a statement and
it must end in a semicolon (;).
10
Variable
• Variables consist of letters and digits, in any order, except that the
first character must be a letter.
• Both upper-and lowercase letters are permitted, though common
usage favors the use of lowercase letters for most types of variables.
• Upper- and lowercase letters are not interchangeable (i.e., an
uppercase letter is not equivalent to the corresponding lowercase
letter.)
11
Variable (cont.)
• The underscore character (_) can also be included, and is considered
to be a letter.
• An underscore is often used in the middle of an variable.
• A variable may also begin with an underscore, though this is rarely
done in practice.
12
Variable (cont.)
• Case-sensitive
• COUNT and count are not same
• As a rule, an identifier should contain enough characters so that its
meaning is readily apparent.
• On the other hand, an excessive number of characters should be
avoided.
13
Variable (Cont.)
Variable
Can use letter of
alphabet (A-Z, a-z)
Digits (0-9)
Can not start a variable
name with digit Underscore (_)
The first character must
be a letter
Can not Use any keyword
Can not Use blank space
14
Is it Valid Variable Name?
Apon
apon
apon123
_sojeb_1
1joty
joty-5
this_is_a_long_name
VaReNdRa
15
Is it Valid Variable Name?
4th
“x”
Order-no
My variable
The first character must be letter
Illegal characters (“)
Illegal characters (-)
Illegal characters (blank space)
16
Identifiers
• Identifiers are names that are given to various program
elements, such as variables, functions and arrays.
17
Keywords
• There are certain reserved words, called Keywords, that have
standard, predefined meaning in C
• Can be used only for their intended purpose
• Can't use as identifiers
18
Keywords
19
Expressions
• An expression is a combination of operators and operands.
• C expressions follow the rule of algebra
Expression Operator
Arithmetic Expression +, -, *, /, %
Logical Expression AND, OR, NOT
Relational ==, !=, <, >, <=, >=
20
Assign value to variable
• To assign a value to a variable, put its name to the left of an equal sign (=).
• Put the variable you want to give the variable to the right of the equal sign.
• It is a statement, so end with a ‘;’
variable value
;
21

More Related Content

ODP
CProgrammingTutorial
PPT
PPTX
Introduction to fundamentaals of computing.pptx
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
DOC
PPT
Basics of c
PPT
Basics of C.ppt
PPT
Basics of C.ppt
CProgrammingTutorial
Introduction to fundamentaals of computing.pptx
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
Basics of c
Basics of C.ppt
Basics of C.ppt

Similar to Introduction to Programming Lecture Material 5 (20)

PPT
Basics of C.ppt
PPT
Basics of C.ppt
PPT
Basics of C.ppt
PPT
Funa-C.ppt
PPT
Basics of C (1).ppt
PPT
Basics of C (1).ppt
PPT
C programming basic pdf.ppt
PPT
Basics of C.ppt
PPT
Basiscs of c++ include variable, special characters
PPT
Basics of C.ppt
PPT
Basics of C--C Basics------------------.ppt
PPT
Basics of C.ppt
PPT
Basics of C.ppt
PPTX
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
PPT
Basics of C.ppt
PPT
Basics of C.ppt C PROGRAMMING AND DATA STRUCT
PPT
Basics of C programming power point presentation
PPT
Basics of C.ppt,...................................
PPT
Introduction to Programming Concepts Algorithm Flowchart Introduction to C...
PPT
Basics of C (2).ppt bbbbbbbbbbbbbbbbbbbbb
Basics of C.ppt
Basics of C.ppt
Basics of C.ppt
Funa-C.ppt
Basics of C (1).ppt
Basics of C (1).ppt
C programming basic pdf.ppt
Basics of C.ppt
Basiscs of c++ include variable, special characters
Basics of C.ppt
Basics of C--C Basics------------------.ppt
Basics of C.ppt
Basics of C.ppt
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
Basics of C.ppt
Basics of C.ppt C PROGRAMMING AND DATA STRUCT
Basics of C programming power point presentation
Basics of C.ppt,...................................
Introduction to Programming Concepts Algorithm Flowchart Introduction to C...
Basics of C (2).ppt bbbbbbbbbbbbbbbbbbbbb
Ad

Recently uploaded (20)

PPT
Drone Technology Electronics components_1
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
436813905-LNG-Process-Overview-Short.pptx
PPTX
Simulation of electric circuit laws using tinkercad.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
Queuing formulas to evaluate throughputs and servers
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PPTX
Practice Questions on recent development part 1.pptx
PPT
Project quality management in manufacturing
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Drone Technology Electronics components_1
Model Code of Practice - Construction Work - 21102022 .pdf
436813905-LNG-Process-Overview-Short.pptx
Simulation of electric circuit laws using tinkercad.pptx
573137875-Attendance-Management-System-original
Internship_Presentation_Final engineering.pptx
Lesson 3_Tessellation.pptx finite Mathematics
AgentX UiPath Community Webinar series - Delhi
UNIT-1 - COAL BASED THERMAL POWER PLANTS
OOP with Java - Java Introduction (Basics)
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Queuing formulas to evaluate throughputs and servers
Structs to JSON How Go Powers REST APIs.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
Practice Questions on recent development part 1.pptx
Project quality management in manufacturing
bas. eng. economics group 4 presentation 1.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Ad

Introduction to Programming Lecture Material 5

  • 1. 1 Structure of C Program A C program basically consists of the following parts: • Preprocessor Commands • Functions • Variables • Statements & Expressions • Comments
  • 2. Structure of C Program 2 Preprocessor Commands Main Function Library Function End of Program Comment
  • 3. 3 Preprocessor Commands  These commands tells the compiler to do preprocessing before doing actual compilation.  Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.
  • 4. 4 Functions  Functions are main building blocks of any C Program.  Every C Program will have one or more functions and there is one mandatory function which is called main() function.  The C Programming language provides a set of built-in functions.  In the above example printf() is a C built-in function which is used to print anything on the screen.
  • 5. 5 Comments  Comments are used to give additional useful information inside a C Program.  All the comments will be put inside /*...*/ as given in the example above.  A comment can span through multiple lines. /* comment for multiple line */ // single line comment
  • 6. 6 Variable and Variable Declaration • Variable is a named memory location that can hold various values. • All variables must be declared before they can be used. • When we declare a variable, we tell the compiler what type of variable is being used. • A declaration associates a group of variables with a specific data type.
  • 7. 7 Structure of C Program Preprocessor Commands Main Function Library Function End of Program Comment
  • 8. 8 C’s Basic Data Type Type Keyword format Specifier Memory Requirements Character data char %c 1 Byte Signed whole numbers int %d 2 or 4 Byte Floating-point numbers float %f 4 Byte Double-precision floating- point number double %lf 8 Byte valueless void ---
  • 9. 9 How to Declare Variables •To declare a variable, use this general form: type var-name; •In C, a variable declaration is a statement and it must end in a semicolon (;).
  • 10. 10 Variable • Variables consist of letters and digits, in any order, except that the first character must be a letter. • Both upper-and lowercase letters are permitted, though common usage favors the use of lowercase letters for most types of variables. • Upper- and lowercase letters are not interchangeable (i.e., an uppercase letter is not equivalent to the corresponding lowercase letter.)
  • 11. 11 Variable (cont.) • The underscore character (_) can also be included, and is considered to be a letter. • An underscore is often used in the middle of an variable. • A variable may also begin with an underscore, though this is rarely done in practice.
  • 12. 12 Variable (cont.) • Case-sensitive • COUNT and count are not same • As a rule, an identifier should contain enough characters so that its meaning is readily apparent. • On the other hand, an excessive number of characters should be avoided.
  • 13. 13 Variable (Cont.) Variable Can use letter of alphabet (A-Z, a-z) Digits (0-9) Can not start a variable name with digit Underscore (_) The first character must be a letter Can not Use any keyword Can not Use blank space
  • 14. 14 Is it Valid Variable Name? Apon apon apon123 _sojeb_1 1joty joty-5 this_is_a_long_name VaReNdRa
  • 15. 15 Is it Valid Variable Name? 4th “x” Order-no My variable The first character must be letter Illegal characters (“) Illegal characters (-) Illegal characters (blank space)
  • 16. 16 Identifiers • Identifiers are names that are given to various program elements, such as variables, functions and arrays.
  • 17. 17 Keywords • There are certain reserved words, called Keywords, that have standard, predefined meaning in C • Can be used only for their intended purpose • Can't use as identifiers
  • 19. 19 Expressions • An expression is a combination of operators and operands. • C expressions follow the rule of algebra Expression Operator Arithmetic Expression +, -, *, /, % Logical Expression AND, OR, NOT Relational ==, !=, <, >, <=, >=
  • 20. 20 Assign value to variable • To assign a value to a variable, put its name to the left of an equal sign (=). • Put the variable you want to give the variable to the right of the equal sign. • It is a statement, so end with a ‘;’ variable value ;
  • 21. 21