SlideShare a Scribd company logo
Structure Of a C Program
David Livingston J,
davidjlivingston@gmail.com &
Staff members of
Department of CE/IT, M.S.P.V.L PC
Structure of a C program
#include <stdio.h>
void main (void)
{
printf(“nHello Worldn”);
}
Preprocessor directive (header file)
Program statement
#include <stdio.h>
#define VALUE 10
int global_var;
void main (void)
{
/* This is the beginning of the program */
int local_var;
local_var = 5;
global_var = local_var + VALUE;
printf (“Total sum is: %dn”, global_var); // Print out the result
}
} Preprocessor
directive
Global variable declaration
Comments
Local variable declaration
Variable definition
Preprocessor Directives
• The first statement to be checked by the compiler
• Preprocessor Directives always preceded with ‘#’ sign
• They contain information to the compiler which are required by
the compiler during compilation.
• There are a few compiler directives. But only 2 of them will be
discussed here.
– #include <stdio.h>
• Tells the compiler to include the file stdio.h during compilation
• Anything in the header file will be included a part of the program
– #define VALUE 10
• Tells the compiler to substitute the word VALUE with 10 during compilation
Preprocessor Directives
#define PI 3.141592654
main() {
…..
perimeter = 2*PI*radius;
area = PI*radius*radius;
…...
}
main() {
…..
perimeter = 2* 3.141592654 *radius;
area = 3.141592654 *radius*radius;
…...
}
The result of the compilation is the
same for both C program (One with
#define and the other without it).
Which one is preferred (less typing)?
Which one is more readable?
The one with constant definition using
#define preprocessor directive.
Before compilation, the pre-processor
will replace all PI with 3.141592654.
Comments
• Comment means explanations or annotations that are
included in a program for documentation and
clarification purpose.
• Comments are completely ignored by the compiler
during compilation and have no effect on program
execution.
• Comments starts with ‘/*’ and ends with ‘*/’
• Some compiler support comments starting with ‘//’
Basic Data Types
• There are 3 Basic data types in C:
– int (used to declare numeric program variables of integer type)
– char (used to declare character variable)
– double (used to declare floating point variable)
• In addition, there are float, void, short, long, etc.
• Variables are declared before they are used in a program.
Declaration specifies the type of a variable.
– Example: int local_var;
• Once defined variables are used for storing a value.
Variable
• A variable can be declared globally or locally.
• A globally declared variable can be accessed from
any part of the program.
• A locally declared variable can only be accessed
from inside the function in which the variable is
declared.
Statements
• A specification of an action to be taken by the
computer as the program executes is called a
Statement.
• In the previous example, there are 2 lines following
variable declaration that terminate with semicolon ‘;’
are statements:
global_var = local_var + VALUE;
printf (“Total sum is: %dn”, global_var);
• Each line is a statement that end with a semicolon is a
Basic Functions
• A C program consists of one or more functions that contain
a group of statements which perform a specific task.
• A C program must at least have one function: the function
main.
• We can create our own function or use the functions that
has been declared in C library (called Predefined function).
• In order to use Predefined functions, we have to include
the appropriate header file (example: stdio.h).
• In this section, we will learn a few functions that are
pre-defined in the header file stdio.h
• These functions are:
– printf()
– scanf()
– getchar() & putchar()
• In addition to those functions, we will also learn about
Format Specifier and Escape Sequence which are
used with printf() and scanf().
printf()
• Used to send data to the standard output (usually the
monitor) to be printed according to specific format.
• General format:
– printf(“control string”, variables);
• Control string is a combination of text, format specifier
and escape sequence.
• Example:
– printf(“Thank you”);
– printf (“Total sum is: %dn”, global_var);
• %d is a format Specifier
• n is an escape sequence
Format Specifier
No Format Specifier Output Type Output Example
1 %d Signed decimal integer 76
2 %i Signed decimal integer 76
3 %o Unsigned octal integer 134
4 %u Unsigned decimal integer 76
5 %x Unsigned hexadecimal (small letter) 9c
6 %X Unsigned hexadecimal (capital letter) 9C
7 %f Integer including decimal point 76.0000
8 %e Signed floating point (using e notation) 7.6000e+01
9 %E Signed floating point (using E notation) 7.6000E+01
10 %g The shorter between %f and %e 76
11 %G The shorter between %f and %E 76
12 %x Character ‘7’
13 %s String ‘76'
Tells the printf() function the format of the output to be printed put.
Escape Sequence
Escape Sequence Effect
a Beep sound
b Backspace
f Formfeed (for printing)
n New line
r Carriage return
t Tab
v Vertical tab
 Backslash
” “ sign
o Octal decimal
x Hexadecimal
O NULL
Escape sequence is used in the printf() function to do something to
the output.
scanf()
• Reads data from the standard input device (usually keyboard)
and store it in a variable. The General format is:
– scanf(“Control string”, &variable);
• The general format is pretty much the same as printf() except
that it passes the address of the variable (notice the & sign)
instead of the variable itself to the second function argument.
• Example:
int age;
printf(“Enter your age: “);
scanf(“%d”, &age);
getchar() and putchar()
• getchar() - reads a character from standard input
• putchar() - writes a character to standard output
• Example:
#include <stdio.h>
void main(void)
{
char my_char;
printf(“Please type a character: “);
my_char = getchar();
printf(“nYou have typed this character: “);
putchar(my_char);
}
The End
Thank U

More Related Content

What's hot

Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
C keywords and identifiers
C keywords and identifiersC keywords and identifiers
C keywords and identifiers
Akhileshwar Reddy Ankireddy
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
C functions
C functionsC functions
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 

What's hot (20)

Functions in c language
Functions in c language Functions in c language
Functions in c language
 
C keywords and identifiers
C keywords and identifiersC keywords and identifiers
C keywords and identifiers
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
C functions
C functionsC functions
C functions
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
String functions in C
String functions in CString functions in C
String functions in C
 

Viewers also liked

Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Structure c
Structure cStructure c
Structure c
thirumalaikumar3
 
Structure in C
Structure in CStructure in C
Structure in C
Fazle Rabbi Ador
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
String c
String cString c
String in c
String in cString in c
String in c
Suneel Dogra
 

Viewers also liked (8)

Strings in C
Strings in CStrings in C
Strings in C
 
Structure c
Structure cStructure c
Structure c
 
Structure in C
Structure in CStructure in C
Structure in C
 
Structure in c
Structure in cStructure in c
Structure in c
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Array in c language
Array in c languageArray in c language
Array in c language
 
String c
String cString c
String c
 
String in c
String in cString in c
String in c
 

Similar to Structure of a C program

Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
424769021-1-First-C-Program-1-ppt (1).ppt
424769021-1-First-C-Program-1-ppt (1).ppt424769021-1-First-C-Program-1-ppt (1).ppt
424769021-1-First-C-Program-1-ppt (1).ppt
advRajatSharma
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
C programming
C programmingC programming
C programming
PralhadKhanal1
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
Md. Ashikur Rahman
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAlpana Gupta
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
RSathyaPriyaCSEKIOT
 
Programming in C
Programming in CProgramming in C
Programming in C
Nishant Munjal
 
C fundamentals
C fundamentalsC fundamentals
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 

Similar to Structure of a C program (20)

Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
424769021-1-First-C-Program-1-ppt (1).ppt
424769021-1-First-C-Program-1-ppt (1).ppt424769021-1-First-C-Program-1-ppt (1).ppt
424769021-1-First-C-Program-1-ppt (1).ppt
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
C programming
C programmingC programming
C programming
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Chapter3
Chapter3Chapter3
Chapter3
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 

More from David Livingston J

Performing Addition and Subtraction on Integers
Performing Addition and Subtraction on IntegersPerforming Addition and Subtraction on Integers
Performing Addition and Subtraction on Integers
David Livingston J
 
Introduction to Bluetooth technology
Introduction to Bluetooth technologyIntroduction to Bluetooth technology
Introduction to Bluetooth technologyDavid Livingston J
 
Past, Present and Future of Mobile Computing
Past, Present and Future of Mobile ComputingPast, Present and Future of Mobile Computing
Past, Present and Future of Mobile ComputingDavid Livingston J
 
Introduction & history of mobile computing
Introduction & history of mobile computingIntroduction & history of mobile computing
Introduction & history of mobile computingDavid Livingston J
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in cDavid Livingston J
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in cDavid Livingston J
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using Computer
David Livingston J
 

More from David Livingston J (8)

Performing Addition and Subtraction on Integers
Performing Addition and Subtraction on IntegersPerforming Addition and Subtraction on Integers
Performing Addition and Subtraction on Integers
 
Introduction to Bluetooth technology
Introduction to Bluetooth technologyIntroduction to Bluetooth technology
Introduction to Bluetooth technology
 
Wireless LAN Technoloy
Wireless LAN TechnoloyWireless LAN Technoloy
Wireless LAN Technoloy
 
Past, Present and Future of Mobile Computing
Past, Present and Future of Mobile ComputingPast, Present and Future of Mobile Computing
Past, Present and Future of Mobile Computing
 
Introduction & history of mobile computing
Introduction & history of mobile computingIntroduction & history of mobile computing
Introduction & history of mobile computing
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using Computer
 

Recently uploaded

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Structure of a C program

  • 1. Structure Of a C Program David Livingston J, davidjlivingston@gmail.com & Staff members of Department of CE/IT, M.S.P.V.L PC
  • 2. Structure of a C program #include <stdio.h> void main (void) { printf(“nHello Worldn”); } Preprocessor directive (header file) Program statement #include <stdio.h> #define VALUE 10 int global_var; void main (void) { /* This is the beginning of the program */ int local_var; local_var = 5; global_var = local_var + VALUE; printf (“Total sum is: %dn”, global_var); // Print out the result } } Preprocessor directive Global variable declaration Comments Local variable declaration Variable definition
  • 3. Preprocessor Directives • The first statement to be checked by the compiler • Preprocessor Directives always preceded with ‘#’ sign • They contain information to the compiler which are required by the compiler during compilation. • There are a few compiler directives. But only 2 of them will be discussed here. – #include <stdio.h> • Tells the compiler to include the file stdio.h during compilation • Anything in the header file will be included a part of the program – #define VALUE 10 • Tells the compiler to substitute the word VALUE with 10 during compilation
  • 4. Preprocessor Directives #define PI 3.141592654 main() { ….. perimeter = 2*PI*radius; area = PI*radius*radius; …... } main() { ….. perimeter = 2* 3.141592654 *radius; area = 3.141592654 *radius*radius; …... } The result of the compilation is the same for both C program (One with #define and the other without it). Which one is preferred (less typing)? Which one is more readable? The one with constant definition using #define preprocessor directive. Before compilation, the pre-processor will replace all PI with 3.141592654.
  • 5. Comments • Comment means explanations or annotations that are included in a program for documentation and clarification purpose. • Comments are completely ignored by the compiler during compilation and have no effect on program execution. • Comments starts with ‘/*’ and ends with ‘*/’ • Some compiler support comments starting with ‘//’
  • 6. Basic Data Types • There are 3 Basic data types in C: – int (used to declare numeric program variables of integer type) – char (used to declare character variable) – double (used to declare floating point variable) • In addition, there are float, void, short, long, etc. • Variables are declared before they are used in a program. Declaration specifies the type of a variable. – Example: int local_var; • Once defined variables are used for storing a value.
  • 7. Variable • A variable can be declared globally or locally. • A globally declared variable can be accessed from any part of the program. • A locally declared variable can only be accessed from inside the function in which the variable is declared.
  • 8. Statements • A specification of an action to be taken by the computer as the program executes is called a Statement. • In the previous example, there are 2 lines following variable declaration that terminate with semicolon ‘;’ are statements: global_var = local_var + VALUE; printf (“Total sum is: %dn”, global_var); • Each line is a statement that end with a semicolon is a
  • 9. Basic Functions • A C program consists of one or more functions that contain a group of statements which perform a specific task. • A C program must at least have one function: the function main. • We can create our own function or use the functions that has been declared in C library (called Predefined function). • In order to use Predefined functions, we have to include the appropriate header file (example: stdio.h).
  • 10. • In this section, we will learn a few functions that are pre-defined in the header file stdio.h • These functions are: – printf() – scanf() – getchar() & putchar() • In addition to those functions, we will also learn about Format Specifier and Escape Sequence which are used with printf() and scanf().
  • 11. printf() • Used to send data to the standard output (usually the monitor) to be printed according to specific format. • General format: – printf(“control string”, variables); • Control string is a combination of text, format specifier and escape sequence. • Example: – printf(“Thank you”); – printf (“Total sum is: %dn”, global_var); • %d is a format Specifier • n is an escape sequence
  • 12. Format Specifier No Format Specifier Output Type Output Example 1 %d Signed decimal integer 76 2 %i Signed decimal integer 76 3 %o Unsigned octal integer 134 4 %u Unsigned decimal integer 76 5 %x Unsigned hexadecimal (small letter) 9c 6 %X Unsigned hexadecimal (capital letter) 9C 7 %f Integer including decimal point 76.0000 8 %e Signed floating point (using e notation) 7.6000e+01 9 %E Signed floating point (using E notation) 7.6000E+01 10 %g The shorter between %f and %e 76 11 %G The shorter between %f and %E 76 12 %x Character ‘7’ 13 %s String ‘76' Tells the printf() function the format of the output to be printed put.
  • 13. Escape Sequence Escape Sequence Effect a Beep sound b Backspace f Formfeed (for printing) n New line r Carriage return t Tab v Vertical tab Backslash ” “ sign o Octal decimal x Hexadecimal O NULL Escape sequence is used in the printf() function to do something to the output.
  • 14. scanf() • Reads data from the standard input device (usually keyboard) and store it in a variable. The General format is: – scanf(“Control string”, &variable); • The general format is pretty much the same as printf() except that it passes the address of the variable (notice the & sign) instead of the variable itself to the second function argument. • Example: int age; printf(“Enter your age: “); scanf(“%d”, &age);
  • 15. getchar() and putchar() • getchar() - reads a character from standard input • putchar() - writes a character to standard output • Example: #include <stdio.h> void main(void) { char my_char; printf(“Please type a character: “); my_char = getchar(); printf(“nYou have typed this character: “); putchar(my_char); }