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' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 
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 - JavaTpointJavaTpoint.Com
 
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.inTIB Academy
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controlsvinay arora
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programminggajendra singh
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
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 LanguageVincenzo De Florio
 
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 1Rumman Ansari
 
OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
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 & ...vtunotesbysree
 
Web application architecture
Web application architectureWeb application architecture
Web application architectureIlio Catallo
 

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

PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxSONU KUMAR
 
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 ValuesRushdi Shams
 
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.SivakumarSivakumar R D .
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
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.pptxAnkitaVerma776806
 
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 structuresPradipta Mishra
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
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 Pradipta Mishra
 
Presentation on 21.11.2022.pptx
Presentation on 21.11.2022.pptxPresentation on 21.11.2022.pptx
Presentation on 21.11.2022.pptxPriyajit Sen
 

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

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 ResearchRushdi Shams
 
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 IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
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 processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi 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 translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi 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

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
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.christianmathematics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
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.pdfNirmal Dwivedi
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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...Pooja Bhuva
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
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).pptxEsquimalt MFRC
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/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
 

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;