SlideShare a Scribd company logo
1 of 36
Structure of C++ program
Documentation section
Linking section
Definition section
Global declaration section
Function
main() functions
Chapter Two
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL1
 Documentation Section: comment parts, which are
ignored by compiler. The comments are used to describe
the functionality of each statement in the program, its
copyright, author, and date of compilation and purpose of
the program to the user.
Syntax: //This statement is a single line comment
/*This is multiline comment*/
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL2
Link section:
 link the necessary files and libraries to current files
 Includes pre-processer directives as well as header
files
Syntax: #include<file or library name>
e.g. #include<iostream.h>
#include<iomap.h>
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL3
Definition Section:
 It is possible to define symbolic constants.
 A symbolic constant is a constant value given to a
name which can't be changed in program
Syntax: #define identifier constant
e.g #define PI 3.14
 Global declaration Section: variables declared under
this section are available throughout the program.
syntax: data type variable
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL4
main ( ) function:
 The execution of the program starts from main function.
 Every program must have only one main function.
 All other functions are called either directly or indirectly
from main
 It is independent from whether it is at the beginning, at the
end or by the middle of the code
 its content is always the first to be executed when a
program starts
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL5
Syntax and Semantics
Syntax :
 consists of the rules for the correct use of the language.
 This involves the correct grammatical construction and
arrangement of the language, correct spelling.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL6
 Semantics:
deal with the meanings given to syntactically correct
constructs of the language.
is defined in terms of the program’s run-time behavior
A program could be syntactically correct yet
meaningless
Example
sum=0;
while (sum!=-1)
sum=sum+10;
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL7
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL8
C++ Compilation Process A
 program written in C++ must be translated into a
machine language in order to be executed by a
CPU.
 The process of translating high-level language
into machine language
 The compilation process consists of the following
steps. edit source code -> compile -> link -
> execute (editor) (compiler) (linker)
(loader)
The parts of a simple C++ Program
 C++ program file should be saved with file name extension
“ .CPP ”
 #-is a signal to the preprocessor
 include - is a preprocessor instruction that directs the
compiler to include a copy of the file specified in the angle
brackets in the source code.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL9
Cont’d
 { } : signals the beginning of the main function body and the end
of the main function body
 ; statement ends with semicolon
 Cout: is an object used for printing data to the screen. followed
by the insertion operator also called output redirection operator
(<<)
Syntax: cout<<Object;
Cin:
 used for taking input from the keyboard. followed by the
input redirection operator (>>) also called extraction
operator.
 take value from the keyboard and store it in the memory
Syntax: cin>>Object
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL10
return 0;
 makes the main() function to finish and return the code
that the instruction is followed by, in this case 0.
 most usual way to terminate a program that has not found
any errors during its execution.
Valid names—Identifiers
 Within a program names are used to represent variables,
constants and functions.
 When choosing valid identifiers for your variables,
constants and functions, the following rules will be applied.
1) an identifier contains a series of letters, numbers, or
underscore ( _ )
2) the first character must be a letter or underscore
3) no restriction on the length of an identifier
4) C++ keywords are reserved and can not be used as names
Cont’d
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL11
Comments on C++ programs
 text which explains some aspect of a program.
 Ignored by the compiler
 Their purpose is only to allow the programmer to insert
notes or descriptions embedded within the source code
 C++ provides two types of comment
i. Single Line Comment:
Eg: cout<<var1; //this line prints the value of var1
ii. Multiple Line Comment:
Eg: /*this is a kind of comment where
Multiple lines can be enclosed in
one C++ program */
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL12
Variables and Constants
Variable:
 is a reserved place in memory to store information in.
 is used for holding data values
 All variables have three important properties:
 Data Type: describes the property of the data and the size
of the reserved memory
 Name: used to refer to the value in the variable
 Value: assigning a new value to the variable
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL13
Declaring Variables
 Variables can be created in a process known as declaration.
 Good variable names indicate the purpose of the variable or
they should be self descriptive.
 E.g. int myAge
Syntax: Data type Variable Name;
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL14
Keywords
 having a predefined meaning in the language
 we cannot use them as variable names or any other
purpose other than their predefined usage.
Initializing Variables
 When declaring a variable, its value is by default
undetermined.
 When a variable is assigned a value at the time of
declaration, it is called variable initialization
The syntax is:
Data Type variable name = initial value;
 e.g. int a = 0;
or: int a;
a=0;
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL15
Scope of Variables
There are two types of variable visibilities.
 Global variables:
 are variables that can be referred/ accessed anywhere
in the code, when any function, as long as it is declared
first.
 A variable declared before any function immediately
after the include statements are global variables.
Local Variables:
 the scope of the local variable is limited to the
code level or block within which they are declared.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL16
Characters
 Char in C++ are represented as any value inside
a single quote
 E.g.: ‘x’, ‘A’, ‘5’, ‘a’, etc.
Expressions and Statements
All C++ statements end with a semicolon
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL17
Constants
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL18
 A constant is any expression that has a fixed value.
 Like variables, constants are data storage locations in
the computer memory.
 But, constants, unlike variables their content cannot
be changed after the declaration.
 Constants must be initialized when they are created
by the program, and the programmer can’t assign a
new value to a constant later.
 C++ provides two types of constants: literal and
symbolic constant
e.g int studentperclass=15;
student=class*studentperclass
Operators
is a symbol that makes the
machine to take an action
C++ provides several
categories of operators
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL19
Cont’d
Assignment operator
Arithmetic operator
Relational operator
Logical operator
Increment/decrement
operator
The size of operator
Explicit type casting 11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL20
Assignment operator (=)
Syntax: Operand1=Operand2;
 Compound assignment operators: is the
combination of the assignment operator with
other operators like arithmetic and bit wise
operators.
Example:
(+=, -=, *=, /=, %=, >>=, <<=, &=, ^=)
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL21
Arithmetic operators (+, -, *, /, %)
 Except for remainder or modulo (%), all other arithmetic
operators can accept a mix of integers and real operands
 Integer division always results in an integer outcome.
E.g.:
9/2 gives 4 not 4.5
-9/2 gives -4 not -4.5
 Division of integer by integer will not round off to the next
integer
E.g.:
int cost = 100;
int volume = 80;
double unitPrice = cost/ (double) volume;
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL22
Cont’d
The modulo(%) is an operator that gives the remainder
of a division of two integer values
Relational operator (==, !=, > , <, >=, <=)
Is a comparison of two expressions
The result of a relational operator is a Boolean value
that can only be true or false
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL23
Logical Operators (!, &&, ||)
 Logical negation (!)
is a unary operator
 negates the logical value of its
operand.
If its operand is non zero, it
produces 0, and if it is 0 it
produce 1.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL24
Cont’d
Logical AND (&&)
 produces 0 if one or both of its operands
evaluate to 0 otherwise it produces 1.
Logical OR (||)
 produces 0 if both of its operands
evaluate to 0 otherwise, it produces
1.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL25
Increment/Decrement Operators: (++)
and (--)
The auto increment (++) provide a
convenient way of adding 1 from a
numeric variable.
 auto decrement (--) operators
provide a convenient way of
subtracting 1 from a numeric
variable.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL26
Prefix and Postfix:
prefix :
• is written before the variable.
• is evaluated before the assignment.
 postfix :
• appears after the variable name.
• is evaluated after the assignment.
• Prefix and postfix operators can not be used
at once on a single variable.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL27
The size of() Operator
used for calculating the size of any
data item or type.
It takes a single operands
The outcome is totally machine
dependent.
E.g.:
a = size of(char)
b = size of(int)
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL28
Explicit type casting operators
 allows you to convert a datum of a
given type to another data type.
E.g.
int i;
float f = 3.14;
i = (int)f;  equivalent to i = int(f);
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL29
Operator Precedence
Operators in higher levels take
precedence over operators in
lower levels.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL30
Precedence Table:
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL31
cont’d
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL32
Example
 a = = b + c * d
 a = = (b + c) * d
Debugging
 Correcting programming errors
 Detecting ,checking abnormalities
 Also ,we said step by step procedure to find out
errors and removing it
Programming errors
-three types of errors
 Syntax error
 Runtime error
 Logical error
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL33
Syntax error
This error occurs due to following reason.
 Not following the grammatical rules used in
declaration of identifier.
 Not declaring an identifier used in program.
 Not terminating statement by semicolon
 Not providing equal number of opening and
closing braces etc.
These errors can be rectified by the user as it is
displayed while compiling the program.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL34
Runtime error
This error occurs while running a program by displaying
the message listed below.
 Division by 0.
 Overflow,
 E.g. ,memory issue
 Harmful or malicious applications like computer viruses or
Hadware
 when a program calls too many methods or nested
processes
 Underflow
 is a condition in a computer program where the result of a
calculation is a number of smaller
 occur when the true result of a floating point operation is
smaller in magnitude (that is, closer to zero) than in the target
data type
 underflow also results in not having the result saved in the
memory of the application or device.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL35
Logical error
 This error won’t be displayed on the screen. However it will lead
to display wrong results.
Example: An infinite loop.
#include <iostream.h>
int main(){
int n = 1;
while( n > 0){
cout << n << endl;
n++; }
return 0;
}
 This error lead to abnormal termination of a program or infinite
loop.
 These errors solely depend on the logical thinking of the
programmer and are easy to detect if we follow the line of
execution and determine why the program takes that path of
execution.
11/2/2019
DMU ,INTRON_ TO C++ ECEG SEE IT IN
DETAIL36

More Related Content

What's hot (20)

C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Intro
IntroIntro
Intro
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
 
C Language
C LanguageC Language
C Language
 
Chapter2
Chapter2Chapter2
Chapter2
 
C language
C languageC language
C language
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
C language
C languageC language
C language
 
Handout#11
Handout#11Handout#11
Handout#11
 
Abc c program
Abc c programAbc c program
Abc c program
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
C programming course material
C programming course materialC programming course material
C programming course material
 
Handout#07
Handout#07Handout#07
Handout#07
 
Handout#05
Handout#05Handout#05
Handout#05
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
Assignment11
Assignment11Assignment11
Assignment11
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Handout#02
Handout#02Handout#02
Handout#02
 
Handout#06
Handout#06Handout#06
Handout#06
 
Book ppt
Book pptBook ppt
Book ppt
 

Similar to Chapter 2

Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Project 2 the second project involves/tutorialoutlet
Project 2 the second project involves/tutorialoutletProject 2 the second project involves/tutorialoutlet
Project 2 the second project involves/tutorialoutletMessanz
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++DSCIGDTUW
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 
Notes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsNotes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsWilliam Olivier
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programingAhammed Alamin
 

Similar to Chapter 2 (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
PPs16.pptx
PPs16.pptxPPs16.pptx
PPs16.pptx
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
Book management system
Book management systemBook management system
Book management system
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Project 2 the second project involves/tutorialoutlet
Project 2 the second project involves/tutorialoutletProject 2 the second project involves/tutorialoutlet
Project 2 the second project involves/tutorialoutlet
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
C PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdfC PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdf
 
Unit 2 ppt
Unit 2 pptUnit 2 ppt
Unit 2 ppt
 
Notes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsNotes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculations
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
 

Recently uploaded

Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Recently uploaded (20)

Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Chapter 2

  • 1. Structure of C++ program Documentation section Linking section Definition section Global declaration section Function main() functions Chapter Two 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL1
  • 2.  Documentation Section: comment parts, which are ignored by compiler. The comments are used to describe the functionality of each statement in the program, its copyright, author, and date of compilation and purpose of the program to the user. Syntax: //This statement is a single line comment /*This is multiline comment*/ 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL2
  • 3. Link section:  link the necessary files and libraries to current files  Includes pre-processer directives as well as header files Syntax: #include<file or library name> e.g. #include<iostream.h> #include<iomap.h> 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL3
  • 4. Definition Section:  It is possible to define symbolic constants.  A symbolic constant is a constant value given to a name which can't be changed in program Syntax: #define identifier constant e.g #define PI 3.14  Global declaration Section: variables declared under this section are available throughout the program. syntax: data type variable 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL4
  • 5. main ( ) function:  The execution of the program starts from main function.  Every program must have only one main function.  All other functions are called either directly or indirectly from main  It is independent from whether it is at the beginning, at the end or by the middle of the code  its content is always the first to be executed when a program starts 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL5
  • 6. Syntax and Semantics Syntax :  consists of the rules for the correct use of the language.  This involves the correct grammatical construction and arrangement of the language, correct spelling. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL6
  • 7.  Semantics: deal with the meanings given to syntactically correct constructs of the language. is defined in terms of the program’s run-time behavior A program could be syntactically correct yet meaningless Example sum=0; while (sum!=-1) sum=sum+10; 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL7
  • 8. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL8 C++ Compilation Process A  program written in C++ must be translated into a machine language in order to be executed by a CPU.  The process of translating high-level language into machine language  The compilation process consists of the following steps. edit source code -> compile -> link - > execute (editor) (compiler) (linker) (loader)
  • 9. The parts of a simple C++ Program  C++ program file should be saved with file name extension “ .CPP ”  #-is a signal to the preprocessor  include - is a preprocessor instruction that directs the compiler to include a copy of the file specified in the angle brackets in the source code. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL9
  • 10. Cont’d  { } : signals the beginning of the main function body and the end of the main function body  ; statement ends with semicolon  Cout: is an object used for printing data to the screen. followed by the insertion operator also called output redirection operator (<<) Syntax: cout<<Object; Cin:  used for taking input from the keyboard. followed by the input redirection operator (>>) also called extraction operator.  take value from the keyboard and store it in the memory Syntax: cin>>Object 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL10
  • 11. return 0;  makes the main() function to finish and return the code that the instruction is followed by, in this case 0.  most usual way to terminate a program that has not found any errors during its execution. Valid names—Identifiers  Within a program names are used to represent variables, constants and functions.  When choosing valid identifiers for your variables, constants and functions, the following rules will be applied. 1) an identifier contains a series of letters, numbers, or underscore ( _ ) 2) the first character must be a letter or underscore 3) no restriction on the length of an identifier 4) C++ keywords are reserved and can not be used as names Cont’d 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL11
  • 12. Comments on C++ programs  text which explains some aspect of a program.  Ignored by the compiler  Their purpose is only to allow the programmer to insert notes or descriptions embedded within the source code  C++ provides two types of comment i. Single Line Comment: Eg: cout<<var1; //this line prints the value of var1 ii. Multiple Line Comment: Eg: /*this is a kind of comment where Multiple lines can be enclosed in one C++ program */ 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL12
  • 13. Variables and Constants Variable:  is a reserved place in memory to store information in.  is used for holding data values  All variables have three important properties:  Data Type: describes the property of the data and the size of the reserved memory  Name: used to refer to the value in the variable  Value: assigning a new value to the variable 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL13
  • 14. Declaring Variables  Variables can be created in a process known as declaration.  Good variable names indicate the purpose of the variable or they should be self descriptive.  E.g. int myAge Syntax: Data type Variable Name; 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL14 Keywords  having a predefined meaning in the language  we cannot use them as variable names or any other purpose other than their predefined usage.
  • 15. Initializing Variables  When declaring a variable, its value is by default undetermined.  When a variable is assigned a value at the time of declaration, it is called variable initialization The syntax is: Data Type variable name = initial value;  e.g. int a = 0; or: int a; a=0; 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL15
  • 16. Scope of Variables There are two types of variable visibilities.  Global variables:  are variables that can be referred/ accessed anywhere in the code, when any function, as long as it is declared first.  A variable declared before any function immediately after the include statements are global variables. Local Variables:  the scope of the local variable is limited to the code level or block within which they are declared. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL16
  • 17. Characters  Char in C++ are represented as any value inside a single quote  E.g.: ‘x’, ‘A’, ‘5’, ‘a’, etc. Expressions and Statements All C++ statements end with a semicolon 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL17
  • 18. Constants 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL18  A constant is any expression that has a fixed value.  Like variables, constants are data storage locations in the computer memory.  But, constants, unlike variables their content cannot be changed after the declaration.  Constants must be initialized when they are created by the program, and the programmer can’t assign a new value to a constant later.  C++ provides two types of constants: literal and symbolic constant e.g int studentperclass=15; student=class*studentperclass
  • 19. Operators is a symbol that makes the machine to take an action C++ provides several categories of operators 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL19
  • 20. Cont’d Assignment operator Arithmetic operator Relational operator Logical operator Increment/decrement operator The size of operator Explicit type casting 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL20
  • 21. Assignment operator (=) Syntax: Operand1=Operand2;  Compound assignment operators: is the combination of the assignment operator with other operators like arithmetic and bit wise operators. Example: (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=) 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL21
  • 22. Arithmetic operators (+, -, *, /, %)  Except for remainder or modulo (%), all other arithmetic operators can accept a mix of integers and real operands  Integer division always results in an integer outcome. E.g.: 9/2 gives 4 not 4.5 -9/2 gives -4 not -4.5  Division of integer by integer will not round off to the next integer E.g.: int cost = 100; int volume = 80; double unitPrice = cost/ (double) volume; 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL22
  • 23. Cont’d The modulo(%) is an operator that gives the remainder of a division of two integer values Relational operator (==, !=, > , <, >=, <=) Is a comparison of two expressions The result of a relational operator is a Boolean value that can only be true or false 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL23
  • 24. Logical Operators (!, &&, ||)  Logical negation (!) is a unary operator  negates the logical value of its operand. If its operand is non zero, it produces 0, and if it is 0 it produce 1. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL24
  • 25. Cont’d Logical AND (&&)  produces 0 if one or both of its operands evaluate to 0 otherwise it produces 1. Logical OR (||)  produces 0 if both of its operands evaluate to 0 otherwise, it produces 1. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL25
  • 26. Increment/Decrement Operators: (++) and (--) The auto increment (++) provide a convenient way of adding 1 from a numeric variable.  auto decrement (--) operators provide a convenient way of subtracting 1 from a numeric variable. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL26
  • 27. Prefix and Postfix: prefix : • is written before the variable. • is evaluated before the assignment.  postfix : • appears after the variable name. • is evaluated after the assignment. • Prefix and postfix operators can not be used at once on a single variable. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL27
  • 28. The size of() Operator used for calculating the size of any data item or type. It takes a single operands The outcome is totally machine dependent. E.g.: a = size of(char) b = size of(int) 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL28
  • 29. Explicit type casting operators  allows you to convert a datum of a given type to another data type. E.g. int i; float f = 3.14; i = (int)f;  equivalent to i = int(f); 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL29
  • 30. Operator Precedence Operators in higher levels take precedence over operators in lower levels. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL30
  • 31. Precedence Table: 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL31
  • 32. cont’d 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL32 Example  a = = b + c * d  a = = (b + c) * d
  • 33. Debugging  Correcting programming errors  Detecting ,checking abnormalities  Also ,we said step by step procedure to find out errors and removing it Programming errors -three types of errors  Syntax error  Runtime error  Logical error 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL33
  • 34. Syntax error This error occurs due to following reason.  Not following the grammatical rules used in declaration of identifier.  Not declaring an identifier used in program.  Not terminating statement by semicolon  Not providing equal number of opening and closing braces etc. These errors can be rectified by the user as it is displayed while compiling the program. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL34
  • 35. Runtime error This error occurs while running a program by displaying the message listed below.  Division by 0.  Overflow,  E.g. ,memory issue  Harmful or malicious applications like computer viruses or Hadware  when a program calls too many methods or nested processes  Underflow  is a condition in a computer program where the result of a calculation is a number of smaller  occur when the true result of a floating point operation is smaller in magnitude (that is, closer to zero) than in the target data type  underflow also results in not having the result saved in the memory of the application or device. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL35
  • 36. Logical error  This error won’t be displayed on the screen. However it will lead to display wrong results. Example: An infinite loop. #include <iostream.h> int main(){ int n = 1; while( n > 0){ cout << n << endl; n++; } return 0; }  This error lead to abnormal termination of a program or infinite loop.  These errors solely depend on the logical thinking of the programmer and are easy to detect if we follow the line of execution and determine why the program takes that path of execution. 11/2/2019 DMU ,INTRON_ TO C++ ECEG SEE IT IN DETAIL36