SlideShare a Scribd company logo
Minimal standard C program
int main(void) {
return 0 ;
}
Function header
int main(void)
• Return type
– Integer according to ANSI C standard
• Return 0, for success
• Or better yet, return EXIT_SUCCESS
• Return non-zero, otherwise
• Name of function
• Argument types
– void means no arguments
– More later on (int argc, char *argv[])
C block
• Delimited by “curlies” – { }
– Encloses C statements (more later)
– Starts with variable declarations (more later)
• C90 and C++ are more forgiving
– Can be nested
• Function code must be in a block
Minimal C program with I/O
#include <stdio.h>
int main(void) {
printf("Hello Worldn") ;
return 0 ;
}
Standard libraries
• C has many “standard” libraries
– But they really aren’t part of the “language”
• C preprocessor (cpp)
– Processes lines starting with #
• And some other things
• #include <stdio.h>
– Adds ~900 lines of code needed to use standard I/O
– cpp -E prog.c
• Shows what is added
Printing a line
• printf("3 feet is 36 inchesn") ;
– Writes a line to standard output
• 3 built-in FILE’s of C
– Standard output (stdout)
• Normal terminal output
– Standard error (stderr)
• Terminal output for errors
– Standard input (stdin)
• Terminal input
Escape sequences
Allows inclusion of special characters
n New line
t Horizontal tab
r Line feed
' Single quote
" Double quote
 Backslash
And a few more….
Formatted I/O
• Allows the pretty printing of variable data
– Easy to get started
– But it takes time to master
• Inspired by FORTRAN I/O
– So it enables printing of aligned tables
• printf("Easy as %8.4fn", PI) ;
– Easy as ____3.1416
Variables
• Names and places for data
• Global variables
– Declared outside of blocks
• Local variables
– Declared at beginning of blocks
• In K&R and ANSI C
– Stored on the stack
Variable names
• Can contain
– Letters (upper and lower)
– Digits
– Underscore
• Cannot start with a digit
• Cannot be a keyword
– Like return
Variable declarations
• Type in C
– Integer, floating point, character, …
– Determines space needed for variable
– Determines what kind of add to do
• Integer or IEEE floating?
• Declaration statements
– int lengthInFeet ;
– int x, y, Y, z ;
Assignment statements
• Gives a value to a variable
– variable = expression ;
• For our example
int feet, inches ;
feet = 10 ;
inches = 12*feet ;
The whole program
#include <stdio.h>
int main(void) {
int feet, inches ;
feet = 5 ;
inches = 12*feet ;
printf("% d feet is %d inchesn",
feet, inches) ;
return 0 ;
}
Things that go wrong
• Syntactic error
– Your program isn’t in legal C
• inches = 12 feet ;
• Semantic error
– Your program has a bug
• inches = feet/12 ;
Debuggers
• Programs to “step” through your code
• Linux gcc has gdb
– Must compile with debugging symbols
• gcc -g ……..
– Many features
• Set breakpoint
• Examine variables
– Hard to master
• But worth the effort to learn a little
Phases
• Compiling
– Preprocessor
• Expands #include statements
– Lexical analysis
• Finds the tokens (or words)
– Syntactic analysis
• Finds the expressions, statements, blocks, etc.
– Code generation
• Linking
– Adds in the library routines
• Loading
– Processes DLL’s and relocation (if needed)

More Related Content

Viewers also liked (20)

PDF
Advanced Git
Sergiu-Ioan Ungur
 
PDF
FLTK Summer Course - Part I - First Impact - Exercises
Michel Alves
 
PDF
TMS - Schedule of Presentations and Reports
Michel Alves
 
PDF
Code Refactoring - Live Coding Demo (JavaDay 2014)
Peter Kofler
 
PDF
FLTK Summer Course - Part II - Second Impact
Michel Alves
 
PDF
Using Git on the Command Line
Brian Richards
 
PDF
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
PDF
"Git Hooked!" Using Git hooks to improve your software development process
Polished Geek LLC
 
PPT
Creating Custom Drupal Modules
tanoshimi
 
PDF
FLTK Summer Course - Part VI - Sixth Impact - Exercises
Michel Alves
 
PDF
FLTK Summer Course - Part VIII - Eighth Impact
Michel Alves
 
PDF
FLTK Summer Course - Part II - Second Impact - Exercises
Michel Alves
 
PPTX
Manipulating file in Python
shoukatali500
 
ODP
Servicios web con Python
Manuel Pérez
 
PPT
Introduction to Git Commands and Concepts
Carl Brown
 
PDF
FLTK Summer Course - Part III - Third Impact
Michel Alves
 
PDF
FLTK Summer Course - Part VII - Seventh Impact
Michel Alves
 
PDF
Blisstering drupal module development ppt v1.2
Anil Sagar
 
PDF
Python Fuse
Matteo Bertozzi
 
DOCX
Code of Conduct_formatted
Ms. Milanie Candido-Noriega
 
Advanced Git
Sergiu-Ioan Ungur
 
FLTK Summer Course - Part I - First Impact - Exercises
Michel Alves
 
TMS - Schedule of Presentations and Reports
Michel Alves
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Peter Kofler
 
FLTK Summer Course - Part II - Second Impact
Michel Alves
 
Using Git on the Command Line
Brian Richards
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
"Git Hooked!" Using Git hooks to improve your software development process
Polished Geek LLC
 
Creating Custom Drupal Modules
tanoshimi
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
Michel Alves
 
FLTK Summer Course - Part VIII - Eighth Impact
Michel Alves
 
FLTK Summer Course - Part II - Second Impact - Exercises
Michel Alves
 
Manipulating file in Python
shoukatali500
 
Servicios web con Python
Manuel Pérez
 
Introduction to Git Commands and Concepts
Carl Brown
 
FLTK Summer Course - Part III - Third Impact
Michel Alves
 
FLTK Summer Course - Part VII - Seventh Impact
Michel Alves
 
Blisstering drupal module development ppt v1.2
Anil Sagar
 
Python Fuse
Matteo Bertozzi
 
Code of Conduct_formatted
Ms. Milanie Candido-Noriega
 

Similar to Minimal standard c program (20)

PPTX
Introduction to C Programming language Chapter02.pptx
foxel54542
 
PPT
lec 1 for ITC Introduction to computing and AI
FatimaAijaz6
 
PPTX
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
PDF
Introduction to C programming
Kathmandu University
 
DOCX
fds unit1.docx
AzhagesvaranTamilsel
 
PPT
Lập trình C
Viet NguyenHoang
 
PPT
Presentation 2.ppt
UdhayaKumar175069
 
PPTX
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
PDF
C for Java programmers (part 1)
Dmitry Zinoviev
 
PPTX
Introduction%20C.pptx
20EUEE018DEEPAKM
 
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
PPTX
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
PDF
Module 1_Chapter 2_PPT (1)sasaddsdsds.pdf
anilcsbs
 
PPT
7512635.ppt
ssuserda85e6
 
PDF
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 
PPTX
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
PPT
C Language
Aakash Singh
 
PPTX
c_pro_introduction.pptx
RohitRaj744272
 
PPT
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
PDF
Introduction of c language
farishah
 
Introduction to C Programming language Chapter02.pptx
foxel54542
 
lec 1 for ITC Introduction to computing and AI
FatimaAijaz6
 
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
Introduction to C programming
Kathmandu University
 
fds unit1.docx
AzhagesvaranTamilsel
 
Lập trình C
Viet NguyenHoang
 
Presentation 2.ppt
UdhayaKumar175069
 
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
C for Java programmers (part 1)
Dmitry Zinoviev
 
Introduction%20C.pptx
20EUEE018DEEPAKM
 
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
MUHUMUZAONAN1
 
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
EG20910848921ISAACDU
 
Module 1_Chapter 2_PPT (1)sasaddsdsds.pdf
anilcsbs
 
7512635.ppt
ssuserda85e6
 
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
C Language
Aakash Singh
 
c_pro_introduction.pptx
RohitRaj744272
 
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
Introduction of c language
farishah
 
Ad

Recently uploaded (20)

PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
July Patch Tuesday
Ivanti
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Python basic programing language for automation
DanialHabibi2
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Ad

Minimal standard c program

  • 1. Minimal standard C program int main(void) { return 0 ; }
  • 2. Function header int main(void) • Return type – Integer according to ANSI C standard • Return 0, for success • Or better yet, return EXIT_SUCCESS • Return non-zero, otherwise • Name of function • Argument types – void means no arguments – More later on (int argc, char *argv[])
  • 3. C block • Delimited by “curlies” – { } – Encloses C statements (more later) – Starts with variable declarations (more later) • C90 and C++ are more forgiving – Can be nested • Function code must be in a block
  • 4. Minimal C program with I/O #include <stdio.h> int main(void) { printf("Hello Worldn") ; return 0 ; }
  • 5. Standard libraries • C has many “standard” libraries – But they really aren’t part of the “language” • C preprocessor (cpp) – Processes lines starting with # • And some other things • #include <stdio.h> – Adds ~900 lines of code needed to use standard I/O – cpp -E prog.c • Shows what is added
  • 6. Printing a line • printf("3 feet is 36 inchesn") ; – Writes a line to standard output • 3 built-in FILE’s of C – Standard output (stdout) • Normal terminal output – Standard error (stderr) • Terminal output for errors – Standard input (stdin) • Terminal input
  • 7. Escape sequences Allows inclusion of special characters n New line t Horizontal tab r Line feed ' Single quote " Double quote Backslash And a few more….
  • 8. Formatted I/O • Allows the pretty printing of variable data – Easy to get started – But it takes time to master • Inspired by FORTRAN I/O – So it enables printing of aligned tables • printf("Easy as %8.4fn", PI) ; – Easy as ____3.1416
  • 9. Variables • Names and places for data • Global variables – Declared outside of blocks • Local variables – Declared at beginning of blocks • In K&R and ANSI C – Stored on the stack
  • 10. Variable names • Can contain – Letters (upper and lower) – Digits – Underscore • Cannot start with a digit • Cannot be a keyword – Like return
  • 11. Variable declarations • Type in C – Integer, floating point, character, … – Determines space needed for variable – Determines what kind of add to do • Integer or IEEE floating? • Declaration statements – int lengthInFeet ; – int x, y, Y, z ;
  • 12. Assignment statements • Gives a value to a variable – variable = expression ; • For our example int feet, inches ; feet = 10 ; inches = 12*feet ;
  • 13. The whole program #include <stdio.h> int main(void) { int feet, inches ; feet = 5 ; inches = 12*feet ; printf("% d feet is %d inchesn", feet, inches) ; return 0 ; }
  • 14. Things that go wrong • Syntactic error – Your program isn’t in legal C • inches = 12 feet ; • Semantic error – Your program has a bug • inches = feet/12 ;
  • 15. Debuggers • Programs to “step” through your code • Linux gcc has gdb – Must compile with debugging symbols • gcc -g …….. – Many features • Set breakpoint • Examine variables – Hard to master • But worth the effort to learn a little
  • 16. Phases • Compiling – Preprocessor • Expands #include statements – Lexical analysis • Finds the tokens (or words) – Syntactic analysis • Finds the expressions, statements, blocks, etc. – Code generation • Linking – Adds in the library routines • Loading – Processes DLL’s and relocation (if needed)