SlideShare a Scribd company logo
Structured Programming
C
Mr. Yogabalajee
History of c
1967 – Martin Richards
Developed a BCPL
1970 – Ken Thompson
Developed a Simply B
1972- Dennis Ritchie at Bell
Laboratories
Developed a C
Sample Program
#include<studio.h>
Main()
{
printf (“First Program”)
}
Main() is function
Begging of program
Printf is a inbuilt function
#pre-processor directive
Structure of C Program
// Program to add two numbers
#include <stdio.h> // Preprocessor directive
int main()
{ // Main function
int a = 10, b = 20; // Variable declaration
int sum = a + b; // Executable statement
printf("Sum = %d", sum);
return 0;
}
Character Set
1. Letters
•Uppercase: A to Z
•Lowercase: a to z
2. Digits
•0 to 9
3. Special Characters
•Symbols like: ~ ! @ # % ^ & * ( ) _ -
+ = { } [ ] |  : ; " ' < > , . ? /
4. White Spaces
•Blank space ( )
•Tab (t)
•Newline (n)
5. Escape Sequences
•Represent special characters using a
backslash ()
•n – Newline
•t – Tab
• – Backslash
•' – Single quote
•" – Double quote
C Tokens
Token Type Description Examples
1. Keywords
Predefined, reserved words with
special meaning in C
int, float, if, else, return
2. Identifiers
Names given to variables, functions,
arrays, etc. by the programmer
main, total, sum, mark1
3. Constants
Fixed values that do not change
during program execution
100, 3.14, 'A', "Hello"
4. Operators
Symbols used to perform
operations on data
+, -, *, /, ==, &&, !=
5. Special Symbols
Symbols used in syntax and
structure of C programs
;, {}, (), #, "
6. Separators (Punctuators)
Symbols used to separate
statements and blocks
;, ,, {}, ()
Key words
Data Type Purpose Bytes Format Specifer
int Number 4 %d
char [a-z],[A-Z],[0-9],[*?#
%@!........]
1 %c
float Decimal & scientific
notation
4 %f
double Very big number-
Decimal & scientific
notation
8 %lf
Key words
Identifiers
•Names given by the programmer for variables, functions, arrays, etc.
•Created to make the program readable and meaningful.
•Must follow naming rules:
•First Char Must be a alphabet (or underscore).
•Must consist of only letters, digits, or underscore (_)
•only first 31 characters are significant
•Must not contain white space
•Cannot use keywords as identifiers
•Example: total, main, mark1, display_sum
Constants
•Constants are a fixed values that
do not change during the execution
of Program
•C Supports Several types of
Constants
Integer Constants
•Integer Constant refer to sequence of digits
•There are three type of integers
•Decimal integer constants
•Octal integer constants
•Hexa Decimal integer constants
Decimal Integer Constants
•Consist of a set of digits 0-9 proceded by on optional – or + sign
•Eg: – 234 -456 0 3564588 +23
•White space( ), commas(,) and non digit ($@&) are not permitted
OCTAL INTEGER CONSTANTS
•Any combination of digits from the set 0-7 with leading 0
•Eg: 089 0 078652 023
HEXADECIMAL INTEGER CONSTANTS
•Any sequence of digits proceded by 0x or 0X considered by hexadecimal
integer
•Alphabets – A through F or a through f (A-F represent number 10-15)
•Eg: 0x2 0x4F
Real Constants
•Integer number are inadequate to represent quanitites that vary
continuously, such as disatance, heights, temperatures, prices and
so on
•Eg- 17.548 are real or floating point constant
•Real Number may also be expressed in exponential (or Scientific
notation)
•Eg: 215.65 may be written as 2.1565e2 in exponential notation
Single character Constants
•A single character constant contains a single character enclosed
within a pair of single quotes marks
•Eg- ‘5; ‘X’
•Printf(“%d”,’a’);
Would print the number 97
String Constants
•A String constant is a sequence of character enclosed in double
quotes
•The character may be letters, number,special characters & blank
space
•Eg- “hello” :1985” “Good Class”
Backslash character Constants
•A String constant is a sequence of character enclosed in double
quotes
•The character may be letters, number,special characters & blank
space
•Eg- “hello” :1985” “Good Class”
Variables
• Variables are named storage locations used to store data.
• Value of a variable can change during program execution.
• Must be declared before use with a data type.
Rules for Naming Variables:
1.Must begin with a letter or underscore ( _ )
2.Can include letters, digits, and underscores
3.Cannot start with a digit
4.Cannot use C keywords like int, return
5.Variable names are case-sensitive
Example: int age = 20;
Data type
•In C, a data type defines the type of data a variable can store, such as integers,
decimals, or characters.
•It tells the compiler how much memory to allocate and how to interpret the
stored value.
•Every variable must be declared with a data type before it is used in the program.
•Data types ensure type safety, efficient memory usage, and help prevent
errors.
•ANSI C supports three classes of data types:
1.Primary Data Types – int, float, char, void
2.Derived Data Types – Arrays, Pointers, Functions
3.User-Defined Data Types – struct, union, enum
•Correct use of data types improves program efficiency, readability, and
debuggability.
Data type - Integer Type
•Used to store whole numbers without decimal points.
•Can hold positive or negative values.
•Size: Usually 2 or 4 bytes (system-dependent).
•Format specifier: %d
•Eg : int age = 25;
DATA TYPE - Floating Point Type
•Used to store real numbers (with decimal points).
•Two main types:
•float: 4 bytes, less precision.
•double: 8 bytes, higher precision.
•Format specifiers: %f for float, %lf for double.
•Eg : float pi = 3.14;
Data type - Void Type
•Represents no data type / no value.
•Commonly used:
•For functions that do not return a value.
•To declare generic pointers (void *ptr).
•No memory is allocated for void type
•Eg - void display(); // Function with no return type
DATA TYPE - CHARACTER TYPE
•Used to store a single character.
•Occupies 1 byte of memory.
•Internally stores the ASCII value of the character.
•Format specifier: %c
•Eg- char grade = 'A';
Declaration of Variables in C
•Declaration tells the compiler the variable's name and the type of data it
will store.
•This process allows the compiler to allocate the required memory space for
the variable and ensure that only compatible data types are stored.
•C supports different kinds of variable declarations based on the type of data
and structure of the program.
Primary Type Declaration
• Declares variables using basic data types like int, float,
char, double.
• Syntax: data_type variable_name;
• Can also include initial values at the time of declaration.
• Eg: int age;
• float height = 5.9;
• char grade = 'A';
User-Defined Type Declaration
•Uses custom data types created by the programmer.
•Includes: struct, union, enum, and typedef.
•Allows grouping of different data types under a single unit.
•Used for creating complex and readable programs.
•Eg:
• struct Student {
• int id;
• char name[30];
• };
• typedef int Marks;
• enum Week { Mon, Tue, Wed };
Assigning Values to Variables in C
•Assignment is done using the = operator.
•Syntax: variable_name = value;
•Can assign:
• Constants (e.g., int a = 10;)
• Expressions (e.g., sum = a + b;)
• Another variable's value (e.g., x = y;)
•Can assign value:
• At the time of declaration
• After declaration, anywhere in the program
•Assignment is from right to left (value → variable)
Declaring a Variable as Constant in C
•Use the keyword const to make a variable read-only.
•Syntax: const data_type variable_name = value;
•Once assigned, the value cannot be changed.
•Commonly used for values like:
• Mathematical constants (PI)
• Limits (MAX, MIN)
• Configuration values
•Eg:
• const float PI = 3.14; // Constant for value of π
• const int MAX_STUDENTS = 50; // Maximum number of students
Declaring a Variable as Volatile
•Volatile is a type qualifier in C.
•Used when a variable’s value may change at any time, without
any action by the code.
•Prevents the compiler from applying optimizations that assume the
variable does not change.
•Ensures the variable is always read directly from memory.
•Commonly used in:
• Embedded systems
• Interrupts
• Multi-threading/shared memory

More Related Content

Similar to Basic of Structered Programming in C psd (20)

PPT
constants, variables and datatypes in C
Sahithi Naraparaju
 
PPTX
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
PPTX
unit 1 cpds.pptx
madhurij54
 
PPT
C presentation book
krunal1210
 
PPTX
Module 1:Introduction
nikshaikh786
 
PPT
All C ppt.ppt
JeelBhanderi4
 
PPT
Chapter02.PPTArray.pptxArray.pptxArray.pptx
yatakumar84
 
PPT
Variables, identifiers, constants, declaration in c
GayathriShiva4
 
PPT
C language ppt is a presentation of how to explain the introduction of a c la...
sdsharmila11
 
PPT
THE BASIC CONCEPTS OF C PROGRAMMINGPPT.PPT
shanthabalaji2013
 
PPT
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
PPT
introduction2_programming slides briefly exolained
RumaSinha8
 
PPT
Chapter02.PPT
Chaitanya Jambotkar
 
PPT
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
PPT
c programming 2nd chapter pdf.PPT
KauserJahan6
 
PPTX
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
PPTX
Aniket tore
anikettore1
 
PDF
C Tutorial
Dr.Subha Krishna
 
PPTX
unit2.pptx
sscprep9
 
PPTX
LESSON1-C_programming (1).GRADE 8 LESSONpptx
joachimbenedicttulau
 
constants, variables and datatypes in C
Sahithi Naraparaju
 
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
unit 1 cpds.pptx
madhurij54
 
C presentation book
krunal1210
 
Module 1:Introduction
nikshaikh786
 
All C ppt.ppt
JeelBhanderi4
 
Chapter02.PPTArray.pptxArray.pptxArray.pptx
yatakumar84
 
Variables, identifiers, constants, declaration in c
GayathriShiva4
 
C language ppt is a presentation of how to explain the introduction of a c la...
sdsharmila11
 
THE BASIC CONCEPTS OF C PROGRAMMINGPPT.PPT
shanthabalaji2013
 
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
introduction2_programming slides briefly exolained
RumaSinha8
 
Chapter02.PPT
Chaitanya Jambotkar
 
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
c programming 2nd chapter pdf.PPT
KauserJahan6
 
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
Aniket tore
anikettore1
 
C Tutorial
Dr.Subha Krishna
 
unit2.pptx
sscprep9
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
joachimbenedicttulau
 

More from YogaBalajee1 (8)

PPTX
data base management system basic class pdf
YogaBalajee1
 
PDF
.pdfbio polymers and elastin Bio Medical
YogaBalajee1
 
PPTX
AI Trends in healthcare ppt for bio medial
YogaBalajee1
 
PPTX
AI Trends in healthcare PPT for bio medical eng
YogaBalajee1
 
PPTX
AI Trends in healthcare | Bio Medical Eng
YogaBalajee1
 
PPTX
BME PPT - Nanostructured Metallic implants.pptx
YogaBalajee1
 
PPTX
BME ppt for unit 2 - Shape memory alloys.pptx
YogaBalajee1
 
PPTX
Unit 2 PPT notes for BME - Acrylic polymers.pptx
YogaBalajee1
 
data base management system basic class pdf
YogaBalajee1
 
.pdfbio polymers and elastin Bio Medical
YogaBalajee1
 
AI Trends in healthcare ppt for bio medial
YogaBalajee1
 
AI Trends in healthcare PPT for bio medical eng
YogaBalajee1
 
AI Trends in healthcare | Bio Medical Eng
YogaBalajee1
 
BME PPT - Nanostructured Metallic implants.pptx
YogaBalajee1
 
BME ppt for unit 2 - Shape memory alloys.pptx
YogaBalajee1
 
Unit 2 PPT notes for BME - Acrylic polymers.pptx
YogaBalajee1
 
Ad

Recently uploaded (20)

PPTX
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
drones for disaster prevention response.pptx
NawrasShatnawi1
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PDF
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
PPTX
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
PDF
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPT
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
PDF
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
PPTX
REINFORCEMENT AS CONSTRUCTION MATERIALS.pptx
mohaiminulhaquesami
 
PPT
inherently safer design for engineering.ppt
DhavalShah616893
 
PDF
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
PPTX
site survey architecture student B.arch.
sri02032006
 
PPTX
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
PPTX
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
PDF
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
PPTX
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
drones for disaster prevention response.pptx
NawrasShatnawi1
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
REINFORCEMENT AS CONSTRUCTION MATERIALS.pptx
mohaiminulhaquesami
 
inherently safer design for engineering.ppt
DhavalShah616893
 
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
site survey architecture student B.arch.
sri02032006
 
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
Ad

Basic of Structered Programming in C psd

  • 2. History of c 1967 – Martin Richards Developed a BCPL 1970 – Ken Thompson Developed a Simply B 1972- Dennis Ritchie at Bell Laboratories Developed a C
  • 3. Sample Program #include<studio.h> Main() { printf (“First Program”) } Main() is function Begging of program Printf is a inbuilt function #pre-processor directive
  • 4. Structure of C Program // Program to add two numbers #include <stdio.h> // Preprocessor directive int main() { // Main function int a = 10, b = 20; // Variable declaration int sum = a + b; // Executable statement printf("Sum = %d", sum); return 0; }
  • 5. Character Set 1. Letters •Uppercase: A to Z •Lowercase: a to z 2. Digits •0 to 9 3. Special Characters •Symbols like: ~ ! @ # % ^ & * ( ) _ - + = { } [ ] | : ; " ' < > , . ? / 4. White Spaces •Blank space ( ) •Tab (t) •Newline (n) 5. Escape Sequences •Represent special characters using a backslash () •n – Newline •t – Tab • – Backslash •' – Single quote •" – Double quote
  • 6. C Tokens Token Type Description Examples 1. Keywords Predefined, reserved words with special meaning in C int, float, if, else, return 2. Identifiers Names given to variables, functions, arrays, etc. by the programmer main, total, sum, mark1 3. Constants Fixed values that do not change during program execution 100, 3.14, 'A', "Hello" 4. Operators Symbols used to perform operations on data +, -, *, /, ==, &&, != 5. Special Symbols Symbols used in syntax and structure of C programs ;, {}, (), #, " 6. Separators (Punctuators) Symbols used to separate statements and blocks ;, ,, {}, ()
  • 7. Key words Data Type Purpose Bytes Format Specifer int Number 4 %d char [a-z],[A-Z],[0-9],[*?# %@!........] 1 %c float Decimal & scientific notation 4 %f double Very big number- Decimal & scientific notation 8 %lf
  • 9. Identifiers •Names given by the programmer for variables, functions, arrays, etc. •Created to make the program readable and meaningful. •Must follow naming rules: •First Char Must be a alphabet (or underscore). •Must consist of only letters, digits, or underscore (_) •only first 31 characters are significant •Must not contain white space •Cannot use keywords as identifiers •Example: total, main, mark1, display_sum
  • 10. Constants •Constants are a fixed values that do not change during the execution of Program •C Supports Several types of Constants
  • 11. Integer Constants •Integer Constant refer to sequence of digits •There are three type of integers •Decimal integer constants •Octal integer constants •Hexa Decimal integer constants
  • 12. Decimal Integer Constants •Consist of a set of digits 0-9 proceded by on optional – or + sign •Eg: – 234 -456 0 3564588 +23 •White space( ), commas(,) and non digit ($@&) are not permitted OCTAL INTEGER CONSTANTS •Any combination of digits from the set 0-7 with leading 0 •Eg: 089 0 078652 023 HEXADECIMAL INTEGER CONSTANTS •Any sequence of digits proceded by 0x or 0X considered by hexadecimal integer •Alphabets – A through F or a through f (A-F represent number 10-15) •Eg: 0x2 0x4F
  • 13. Real Constants •Integer number are inadequate to represent quanitites that vary continuously, such as disatance, heights, temperatures, prices and so on •Eg- 17.548 are real or floating point constant •Real Number may also be expressed in exponential (or Scientific notation) •Eg: 215.65 may be written as 2.1565e2 in exponential notation
  • 14. Single character Constants •A single character constant contains a single character enclosed within a pair of single quotes marks •Eg- ‘5; ‘X’ •Printf(“%d”,’a’); Would print the number 97
  • 15. String Constants •A String constant is a sequence of character enclosed in double quotes •The character may be letters, number,special characters & blank space •Eg- “hello” :1985” “Good Class”
  • 16. Backslash character Constants •A String constant is a sequence of character enclosed in double quotes •The character may be letters, number,special characters & blank space •Eg- “hello” :1985” “Good Class”
  • 17. Variables • Variables are named storage locations used to store data. • Value of a variable can change during program execution. • Must be declared before use with a data type. Rules for Naming Variables: 1.Must begin with a letter or underscore ( _ ) 2.Can include letters, digits, and underscores 3.Cannot start with a digit 4.Cannot use C keywords like int, return 5.Variable names are case-sensitive Example: int age = 20;
  • 18. Data type •In C, a data type defines the type of data a variable can store, such as integers, decimals, or characters. •It tells the compiler how much memory to allocate and how to interpret the stored value. •Every variable must be declared with a data type before it is used in the program. •Data types ensure type safety, efficient memory usage, and help prevent errors. •ANSI C supports three classes of data types: 1.Primary Data Types – int, float, char, void 2.Derived Data Types – Arrays, Pointers, Functions 3.User-Defined Data Types – struct, union, enum •Correct use of data types improves program efficiency, readability, and debuggability.
  • 19. Data type - Integer Type •Used to store whole numbers without decimal points. •Can hold positive or negative values. •Size: Usually 2 or 4 bytes (system-dependent). •Format specifier: %d •Eg : int age = 25; DATA TYPE - Floating Point Type •Used to store real numbers (with decimal points). •Two main types: •float: 4 bytes, less precision. •double: 8 bytes, higher precision. •Format specifiers: %f for float, %lf for double. •Eg : float pi = 3.14;
  • 20. Data type - Void Type •Represents no data type / no value. •Commonly used: •For functions that do not return a value. •To declare generic pointers (void *ptr). •No memory is allocated for void type •Eg - void display(); // Function with no return type DATA TYPE - CHARACTER TYPE •Used to store a single character. •Occupies 1 byte of memory. •Internally stores the ASCII value of the character. •Format specifier: %c •Eg- char grade = 'A';
  • 21. Declaration of Variables in C •Declaration tells the compiler the variable's name and the type of data it will store. •This process allows the compiler to allocate the required memory space for the variable and ensure that only compatible data types are stored. •C supports different kinds of variable declarations based on the type of data and structure of the program.
  • 22. Primary Type Declaration • Declares variables using basic data types like int, float, char, double. • Syntax: data_type variable_name; • Can also include initial values at the time of declaration. • Eg: int age; • float height = 5.9; • char grade = 'A';
  • 23. User-Defined Type Declaration •Uses custom data types created by the programmer. •Includes: struct, union, enum, and typedef. •Allows grouping of different data types under a single unit. •Used for creating complex and readable programs. •Eg: • struct Student { • int id; • char name[30]; • }; • typedef int Marks; • enum Week { Mon, Tue, Wed };
  • 24. Assigning Values to Variables in C •Assignment is done using the = operator. •Syntax: variable_name = value; •Can assign: • Constants (e.g., int a = 10;) • Expressions (e.g., sum = a + b;) • Another variable's value (e.g., x = y;) •Can assign value: • At the time of declaration • After declaration, anywhere in the program •Assignment is from right to left (value → variable)
  • 25. Declaring a Variable as Constant in C •Use the keyword const to make a variable read-only. •Syntax: const data_type variable_name = value; •Once assigned, the value cannot be changed. •Commonly used for values like: • Mathematical constants (PI) • Limits (MAX, MIN) • Configuration values •Eg: • const float PI = 3.14; // Constant for value of π • const int MAX_STUDENTS = 50; // Maximum number of students
  • 26. Declaring a Variable as Volatile •Volatile is a type qualifier in C. •Used when a variable’s value may change at any time, without any action by the code. •Prevents the compiler from applying optimizations that assume the variable does not change. •Ensures the variable is always read directly from memory. •Commonly used in: • Embedded systems • Interrupts • Multi-threading/shared memory