SlideShare a Scribd company logo
1 of 21
Lecture 2Lecture 2
Version 1.0Version 1.0
Program StructureProgram Structure
Memory ConceptMemory Concept
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Analyzing C Program Structure IAnalyzing C Program Structure I
#include <stdio.h>#include <stdio.h>
#include <conio.h>#include <conio.h>
void main(){void main(){
clrscr();clrscr();
printf(“This is my first C program n”);printf(“This is my first C program n”);
getch();getch();
}}
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Header fileHeader file
#include <stdio.h>#include <stdio.h>
 C Pre-processorC Pre-processor
 Lines beginning with # are processed by the pre-Lines beginning with # are processed by the pre-
processor before the program is compiledprocessor before the program is compiled
 This line tells the pre-processor to include theThis line tells the pre-processor to include the
contents of the standard input output header filecontents of the standard input output header file
 To compileTo compile library functionlibrary function printf(), it is required.printf(), it is required.
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Header fileHeader file
#include <conio.h>#include <conio.h>
 Required for clrscr() and getch().Required for clrscr() and getch().
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
main ( ) functionmain ( ) function
void main( )void main( )
 It is a part of every C programIt is a part of every C program
 The parenthesis after main indicates that main is aThe parenthesis after main indicates that main is a
program building block called aprogram building block called a functionfunction
 C programs are composed of one or many functionsC programs are composed of one or many functions
like it but main is a mustlike it but main is a must
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Library functionLibrary function
clrscr();clrscr();
 C library function.C library function.
 Clears the contents present in the screen.Clears the contents present in the screen.
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Library functionLibrary function
printf(“This is my first C program n”);printf(“This is my first C program n”);
 C statement.C statement.
 Statements are always terminated with aStatements are always terminated with a semi-colonsemi-colon
 This statement has a library function called printf( )This statement has a library function called printf( )
 It takes aIt takes a stringstring inside of it within twoinside of it within two quotation marksquotation marks
 Whatever is in between them, will be printed on theWhatever is in between them, will be printed on the
screenscreen
 TheThe backslash ()backslash () character is calledcharacter is called Escape CharacterEscape Character
 The escape sequence n meansThe escape sequence n means new linenew line
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
Library functionLibrary function
getch();getch();
 Another C library functionAnother C library function
 When the program compiles and provides an output,When the program compiles and provides an output,
it waits for getting a character from the keyboardit waits for getting a character from the keyboard
 When it gets, it returns from the output screen toWhen it gets, it returns from the output screen to
source codesource code
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Analyzing C Program Structure IIAnalyzing C Program Structure II
/* This program takes two integers/* This program takes two integers
and provides the sum to the user */and provides the sum to the user */
#include <stdio.h>#include <stdio.h> // header file// header file
#include <conio.h>#include <conio.h> //header file//header file
// main function starts// main function starts
void main(){void main(){
clrscr();clrscr(); // clearing the output screen// clearing the output screen
int a,b,sum;int a,b,sum; // declaring three integers a, b and sum// declaring three integers a, b and sum
printf(“Enter integer one: n”);printf(“Enter integer one: n”); // printing on output// printing on output
scanf (“%d”,&a);scanf (“%d”,&a); //taking the input value into a//taking the input value into a
printf(“Enter integer two: n”);printf(“Enter integer two: n”); // printing on output// printing on output
scanf (“%d”,&b);scanf (“%d”,&b); // taking the input value into b// taking the input value into b
sum=a+b;sum=a+b; // taking their summation into sum// taking their summation into sum
printf(“Sum is: %d”, sum);printf(“Sum is: %d”, sum); // displaying the sum// displaying the sum
getch();getch(); //waiting for a character to return//waiting for a character to return
}}
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Multiline commentsMultiline comments
 /* This program takes two integers/* This program takes two integers
 and provides the sum to the user */and provides the sum to the user */
 The characters /* … … … */ is calledThe characters /* … … … */ is called multi-linemulti-line
commentingcommenting
 When C finds this character, it omits what is insideWhen C finds this character, it omits what is inside
that and goes to the next instructionthat and goes to the next instruction
 Comments are required to make the program moreComments are required to make the program more
readable and understandable if anyone analyzes thereadable and understandable if anyone analyzes the
codecode
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Single line commentsSingle line comments
// main function starts// main function starts
 The characters // is calledThe characters // is called single line commentingsingle line commenting
 Again, when C finds this character, it omits that line ofAgain, when C finds this character, it omits that line of
codecode
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Variable declarationVariable declaration
int a, b, sum;int a, b, sum;
 It is aIt is a declarationdeclaration
 The letters a, b and sum are names ofThe letters a, b and sum are names of variablesvariables
 A variable is a location in memory where a value canA variable is a location in memory where a value can
be stored for use by a programbe stored for use by a program
 This declaration specifies that the variables a, b andThis declaration specifies that the variables a, b and
sum are of typesum are of type intint which means that these variableswhich means that these variables
will hold integer valueswill hold integer values
 All variables must be declared with aAll variables must be declared with a namename and aand a datadata
typetype
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Notes on variable namesNotes on variable names
 A variable name in C is anyA variable name in C is any identifieridentifier. An identifier is a. An identifier is a
series of characters consisting of letters, digits andseries of characters consisting of letters, digits and
underscores (_) that does not begin with a digit.underscores (_) that does not begin with a digit.
 It can be of any length. But C will understand the firstIt can be of any length. But C will understand the first
31 characters only.31 characters only.
 C isC is case sensitivecase sensitive. Variable names like A1 and a1 are two. Variable names like A1 and a1 are two
different variables.different variables.
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Library functionLibrary function
scanf (“%d”,&a);scanf (“%d”,&a);
 scanf () function to obtain a value from the userscanf () function to obtain a value from the user
 The scanf () here has twoThe scanf () here has two argumentsarguments.. “%d”“%d” and &and &aa..
 The % is Escape Character and %d is EscapeThe % is Escape Character and %d is Escape
SequenceSequence
 The second argument & (ampersand)- calledThe second argument & (ampersand)- called addressaddress
operatoroperator in C followed by the variable name- tells‑in C followed by the variable name- tells‑
scanf() the location in memory in which the variable ascanf() the location in memory in which the variable a
is stored.is stored.
 The computer then stores the values forThe computer then stores the values for aa at thatat that
locationlocation
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Use of binary operatorsUse of binary operators
sum=a+b;sum=a+b;
 It calculates the sum of variablesIt calculates the sum of variables aa andand bb and assignsand assigns
the result to variable sum using the assignmentthe result to variable sum using the assignment
operator =operator =
 The + and = operators are calledThe + and = operators are called binary operatorsbinary operators asas
they require twothey require two operandsoperands
 The two operands of + are a and b and two operandsThe two operands of + are a and b and two operands
of = are sum and a+bof = are sum and a+b
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
int a,b,sum;int a,b,sum;
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
scanf (“%d”,&a);scanf (“%d”,&a);
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
scanf (“%d”,&a);scanf (“%d”,&a);
Say the input is 100Say the input is 100
19Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
scanf (“%d”,&b);scanf (“%d”,&b);
20Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
scanf (“%d”,&b);scanf (“%d”,&b);
Say the input is 50Say the input is 50
21Rushdi Shams, Dept of CSE, KUET, Bangladesh
Memory conceptMemory concept
sum=a+b;sum=a+b;

More Related Content

What's hot

C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
vinay arora
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 

What's hot (20)

'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C programming
C programmingC programming
C programming
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Deep C
Deep CDeep C
Deep C
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 

Similar to Lec 02. C Program Structure / C Memory Concept

Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
Rushdi Shams
 

Similar to Lec 02. C Program Structure / C Memory Concept (20)

PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptx
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
What is c
What is cWhat is c
What is c
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Structures-2
Structures-2Structures-2
Structures-2
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C programming
C programmingC programming
C programming
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
Presentation on 21.11.2022.pptx
Presentation on 21.11.2022.pptxPresentation on 21.11.2022.pptx
Presentation on 21.11.2022.pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 

More from Rushdi Shams

Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
Rushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
Rushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Lec 02. C Program Structure / C Memory Concept

  • 1. Lecture 2Lecture 2 Version 1.0Version 1.0 Program StructureProgram Structure Memory ConceptMemory Concept
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Analyzing C Program Structure IAnalyzing C Program Structure I #include <stdio.h>#include <stdio.h> #include <conio.h>#include <conio.h> void main(){void main(){ clrscr();clrscr(); printf(“This is my first C program n”);printf(“This is my first C program n”); getch();getch(); }}
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Header fileHeader file #include <stdio.h>#include <stdio.h>  C Pre-processorC Pre-processor  Lines beginning with # are processed by the pre-Lines beginning with # are processed by the pre- processor before the program is compiledprocessor before the program is compiled  This line tells the pre-processor to include theThis line tells the pre-processor to include the contents of the standard input output header filecontents of the standard input output header file  To compileTo compile library functionlibrary function printf(), it is required.printf(), it is required.
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Header fileHeader file #include <conio.h>#include <conio.h>  Required for clrscr() and getch().Required for clrscr() and getch().
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh main ( ) functionmain ( ) function void main( )void main( )  It is a part of every C programIt is a part of every C program  The parenthesis after main indicates that main is aThe parenthesis after main indicates that main is a program building block called aprogram building block called a functionfunction  C programs are composed of one or many functionsC programs are composed of one or many functions like it but main is a mustlike it but main is a must
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Library functionLibrary function clrscr();clrscr();  C library function.C library function.  Clears the contents present in the screen.Clears the contents present in the screen.
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Library functionLibrary function printf(“This is my first C program n”);printf(“This is my first C program n”);  C statement.C statement.  Statements are always terminated with aStatements are always terminated with a semi-colonsemi-colon  This statement has a library function called printf( )This statement has a library function called printf( )  It takes aIt takes a stringstring inside of it within twoinside of it within two quotation marksquotation marks  Whatever is in between them, will be printed on theWhatever is in between them, will be printed on the screenscreen  TheThe backslash ()backslash () character is calledcharacter is called Escape CharacterEscape Character  The escape sequence n meansThe escape sequence n means new linenew line
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Library functionLibrary function getch();getch();  Another C library functionAnother C library function  When the program compiles and provides an output,When the program compiles and provides an output, it waits for getting a character from the keyboardit waits for getting a character from the keyboard  When it gets, it returns from the output screen toWhen it gets, it returns from the output screen to source codesource code
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Analyzing C Program Structure IIAnalyzing C Program Structure II /* This program takes two integers/* This program takes two integers and provides the sum to the user */and provides the sum to the user */ #include <stdio.h>#include <stdio.h> // header file// header file #include <conio.h>#include <conio.h> //header file//header file // main function starts// main function starts void main(){void main(){ clrscr();clrscr(); // clearing the output screen// clearing the output screen int a,b,sum;int a,b,sum; // declaring three integers a, b and sum// declaring three integers a, b and sum printf(“Enter integer one: n”);printf(“Enter integer one: n”); // printing on output// printing on output scanf (“%d”,&a);scanf (“%d”,&a); //taking the input value into a//taking the input value into a printf(“Enter integer two: n”);printf(“Enter integer two: n”); // printing on output// printing on output scanf (“%d”,&b);scanf (“%d”,&b); // taking the input value into b// taking the input value into b sum=a+b;sum=a+b; // taking their summation into sum// taking their summation into sum printf(“Sum is: %d”, sum);printf(“Sum is: %d”, sum); // displaying the sum// displaying the sum getch();getch(); //waiting for a character to return//waiting for a character to return }}
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Multiline commentsMultiline comments  /* This program takes two integers/* This program takes two integers  and provides the sum to the user */and provides the sum to the user */  The characters /* … … … */ is calledThe characters /* … … … */ is called multi-linemulti-line commentingcommenting  When C finds this character, it omits what is insideWhen C finds this character, it omits what is inside that and goes to the next instructionthat and goes to the next instruction  Comments are required to make the program moreComments are required to make the program more readable and understandable if anyone analyzes thereadable and understandable if anyone analyzes the codecode
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Single line commentsSingle line comments // main function starts// main function starts  The characters // is calledThe characters // is called single line commentingsingle line commenting  Again, when C finds this character, it omits that line ofAgain, when C finds this character, it omits that line of codecode
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Variable declarationVariable declaration int a, b, sum;int a, b, sum;  It is aIt is a declarationdeclaration  The letters a, b and sum are names ofThe letters a, b and sum are names of variablesvariables  A variable is a location in memory where a value canA variable is a location in memory where a value can be stored for use by a programbe stored for use by a program  This declaration specifies that the variables a, b andThis declaration specifies that the variables a, b and sum are of typesum are of type intint which means that these variableswhich means that these variables will hold integer valueswill hold integer values  All variables must be declared with aAll variables must be declared with a namename and aand a datadata typetype
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Notes on variable namesNotes on variable names  A variable name in C is anyA variable name in C is any identifieridentifier. An identifier is a. An identifier is a series of characters consisting of letters, digits andseries of characters consisting of letters, digits and underscores (_) that does not begin with a digit.underscores (_) that does not begin with a digit.  It can be of any length. But C will understand the firstIt can be of any length. But C will understand the first 31 characters only.31 characters only.  C isC is case sensitivecase sensitive. Variable names like A1 and a1 are two. Variable names like A1 and a1 are two different variables.different variables.
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Library functionLibrary function scanf (“%d”,&a);scanf (“%d”,&a);  scanf () function to obtain a value from the userscanf () function to obtain a value from the user  The scanf () here has twoThe scanf () here has two argumentsarguments.. “%d”“%d” and &and &aa..  The % is Escape Character and %d is EscapeThe % is Escape Character and %d is Escape SequenceSequence  The second argument & (ampersand)- calledThe second argument & (ampersand)- called addressaddress operatoroperator in C followed by the variable name- tells‑in C followed by the variable name- tells‑ scanf() the location in memory in which the variable ascanf() the location in memory in which the variable a is stored.is stored.  The computer then stores the values forThe computer then stores the values for aa at thatat that locationlocation
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Use of binary operatorsUse of binary operators sum=a+b;sum=a+b;  It calculates the sum of variablesIt calculates the sum of variables aa andand bb and assignsand assigns the result to variable sum using the assignmentthe result to variable sum using the assignment operator =operator =  The + and = operators are calledThe + and = operators are called binary operatorsbinary operators asas they require twothey require two operandsoperands  The two operands of + are a and b and two operandsThe two operands of + are a and b and two operands of = are sum and a+bof = are sum and a+b
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept int a,b,sum;int a,b,sum;
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept scanf (“%d”,&a);scanf (“%d”,&a);
  • 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept scanf (“%d”,&a);scanf (“%d”,&a); Say the input is 100Say the input is 100
  • 19. 19Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept scanf (“%d”,&b);scanf (“%d”,&b);
  • 20. 20Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept scanf (“%d”,&b);scanf (“%d”,&b); Say the input is 50Say the input is 50
  • 21. 21Rushdi Shams, Dept of CSE, KUET, Bangladesh Memory conceptMemory concept sum=a+b;sum=a+b;