SlideShare a Scribd company logo
Hello World!
Getting Started with C++
January 13, 2021
Mansi Sharma (Mentor, DSA)
Garima (Project Coordinator, DSA)
(Developer Students Club IGDTUW)
A compiler is a special program that
processes statements written in a
particular programming language and turns
them into machine language or "code" that
a computer's processor uses.
COMPILER
FIRST PROGRAM
#include<iostream>
using namespace std;
int main () {
cout << "Hello World";
}
VARIABLES
A variable is a name given to a memory location. It is the
basic unit of storage in a program.
•The value stored in a variable can be changed during
program execution.
•A variable is only a name given to a memory location, all
the operations done on the variable effects that memory
location.
•In C++, all the variables must be declared before use.
RULES FOR NAMING VARIABLES IN C++
• Variable names in C++ can range from 1 to 255
characters.
• All variable names must begin with a letter of the
alphabet or an underscore(_).
• After the first initial letter, variable names can also
contain letters and numbers.
• Variable names are case sensitive.
• No spaces or special characters are allowed.
• You cannot use a C++ keyword (a reserved word) as a
variable name.
In C++, data types are declarations for variables. This
determines the type and size of data associated with
variables.
DATATYPES
IDENTIFIERS
The C++ identifier is a name used to identify a
variable, function, class, module, or any other user-
defined item. An identifier starts with a letter A to Z
or a to z or an underscore (_) followed by zero or
more letters, underscores, and digits (0 to 9)
KEYWORDS IN C++
A keyword is a reserved word. You cannot use it as a variable
name, constant name etc. A list of 32 Keywords in C++
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
OPERATORS IN C++
An operator is a symbol that tells the compiler to perform
specific mathematical or logical manipulations. C++ is rich in
built-in operators and provide the following types of operators −
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
Types of Errors
Syntax Errors
● These are generated when C++ grammatical rules are violated. Example, missing
semicolon, incorrect operators in cin and cout, compound statement {} missing,
etc.
● Shown at the time of compilation
#include<iostream>
using namespace std;
void main()
{
int x = 10;
int y = 15;
cout << x << y // semicolon missed
}
Semantic Errors
● These are generated when C++ statements become meaningless. Example:
b + c = a (expressions don't generate value for variables).
● Value is not assigned to expressions
#include<iostream>
using namespace std;
void main()
{
int a, b, c;
a + b = c; // semantic error
}
error: lvalue required as left operand of assignment
a + b = c; //semantic error
Type Errors
● These are generated when a variable is assigned wrong data type. Example: int
value into string.
● Shown at the time of compilation.
#include<iostream>
using namespace std;
void main()
{
int x = "hello"; // type error
}
Runtime Errors
● These are generated at the time of execution of program. Example: file not found,
division by zero.
● Shown at run time
#include<iostream>
using namespace std;
void main()
{
int x = 10;
int y = 0;
cout << x / y; // division by zero
}
Logical Errors
● These errors cause a program to generate wrong output.
● Maybe your understanding of the underlying program is flawed; maybe you didn’t
write what you thought you wrote. Example: wrong formula for Simple Interest.
#include<iostream>
using namespace std;
void main()
{
int principal = 1000, rate = 2, time = 1 ;
int si = principal * rate * 100 / time; // wrong formula
cout << si;
}
Find errors in the
following code
snippets
int main()
{
int i = 10; j = 5;
int modResult = 0;
int divResult = 0;
modResult = i % j;
cout << modResult << " ";
divResult = i / modResult;
cout << divResult;
return 0;
}
#include<iostream>
using namespace std;
void main()
{
cout << 'C++ Programming
questions';
int x = 10, y = 5;
int ans = x / (y - y);
cout << ans
return 0;
}
#include<iostream>
using namespace std;
void main()
{
a,b,s int;
d float;
cout<<"The end of the
program";
return 0;
}
Wisdom of the Wizards
Programs must be
written for people to
read, and only
incidentally for
machines to execute.
Any fool can write code
that a computer can
understand. Good
programmers write
code that humans can
understand.
Minimise time
needed by someone
else to understand a
piece of your code.
Remember that
someone else may be
you, six months after
writing the code.
Naming is 90% of Programming
● Separate names for readability with underscores or hyphens or capitalization
● Coding standards apply
● Use is and has as boolean name prefixes
● Avoid negative names
● Add necessary detail in name: response_time_ms
● Avoid ambiguity: bool read_file, no_items
Practice Questions
Question 1
Write a program to input marks of five
subjects and calculate average.
Question 2
Write a program to enter temperature in degree
fahrenheit and change it into degree celcius.
Question 3
Write a program to enter three numbers and
find greatest number using ternary operators.
Question 4
Write a program to enter two numbers and
swap their values.
Thank You!

More Related Content

What's hot

# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
Dr. Prashant Vats
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
neosphere
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
Bharat Kalia
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh Dalvi
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
eShikshak
 
C language
C languageC language
C language
Mohamed Bedair
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
Himanshu Kaushik
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
Waqar Younis
 
C programming
C programmingC programming
C programming
RubaNagarajan
 
C++ Training
C++ TrainingC++ Training
C++ Training
SubhendraBasu5
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang newZeeshan Ahmad
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 

What's hot (20)

Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
 
C language
C languageC language
C language
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
C programming
C programmingC programming
C programming
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang new
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 

Similar to Hello world! Intro to C++

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
sajjad ali khan
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
JosephAlex21
 
C programming
C programmingC programming
C prog ppt
C prog pptC prog ppt
C prog ppt
xinoe
 
C programming
C programmingC programming
C programming
Rounak Samdadia
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
cpjcollege
 
C++
C++C++
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
Marco Izzotti
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
DineshDhuri4
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
Mohammad Golyani
 
C programming
C programmingC programming
C programming
PralhadKhanal1
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
valerie5142000
 
Oops presentation
Oops presentationOops presentation
Oops presentation
sushamaGavarskar1
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 

Similar to Hello world! Intro to C++ (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
C programming
C programmingC programming
C programming
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C programming
C programmingC programming
C programming
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++
C++C++
C++
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
Chapter2
Chapter2Chapter2
Chapter2
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
C programming
C programmingC programming
C programming
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 

Recently uploaded

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Ethernet Routing and switching chapter 1.ppt
Ethernet Routing and switching chapter 1.pptEthernet Routing and switching chapter 1.ppt
Ethernet Routing and switching chapter 1.ppt
azkamurat
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 

Recently uploaded (20)

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Ethernet Routing and switching chapter 1.ppt
Ethernet Routing and switching chapter 1.pptEthernet Routing and switching chapter 1.ppt
Ethernet Routing and switching chapter 1.ppt
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 

Hello world! Intro to C++

  • 1. Hello World! Getting Started with C++ January 13, 2021 Mansi Sharma (Mentor, DSA) Garima (Project Coordinator, DSA) (Developer Students Club IGDTUW)
  • 2. A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses. COMPILER
  • 3. FIRST PROGRAM #include<iostream> using namespace std; int main () { cout << "Hello World"; }
  • 4. VARIABLES A variable is a name given to a memory location. It is the basic unit of storage in a program. •The value stored in a variable can be changed during program execution. •A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. •In C++, all the variables must be declared before use.
  • 5. RULES FOR NAMING VARIABLES IN C++ • Variable names in C++ can range from 1 to 255 characters. • All variable names must begin with a letter of the alphabet or an underscore(_). • After the first initial letter, variable names can also contain letters and numbers. • Variable names are case sensitive. • No spaces or special characters are allowed. • You cannot use a C++ keyword (a reserved word) as a variable name.
  • 6. In C++, data types are declarations for variables. This determines the type and size of data associated with variables. DATATYPES
  • 7. IDENTIFIERS The C++ identifier is a name used to identify a variable, function, class, module, or any other user- defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9)
  • 8. KEYWORDS IN C++ A keyword is a reserved word. You cannot use it as a variable name, constant name etc. A list of 32 Keywords in C++ auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
  • 9. OPERATORS IN C++ An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provide the following types of operators − • Arithmetic Operators • Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators
  • 10. Types of Errors Syntax Errors ● These are generated when C++ grammatical rules are violated. Example, missing semicolon, incorrect operators in cin and cout, compound statement {} missing, etc. ● Shown at the time of compilation #include<iostream> using namespace std; void main() { int x = 10; int y = 15; cout << x << y // semicolon missed }
  • 11. Semantic Errors ● These are generated when C++ statements become meaningless. Example: b + c = a (expressions don't generate value for variables). ● Value is not assigned to expressions #include<iostream> using namespace std; void main() { int a, b, c; a + b = c; // semantic error } error: lvalue required as left operand of assignment a + b = c; //semantic error
  • 12. Type Errors ● These are generated when a variable is assigned wrong data type. Example: int value into string. ● Shown at the time of compilation. #include<iostream> using namespace std; void main() { int x = "hello"; // type error }
  • 13. Runtime Errors ● These are generated at the time of execution of program. Example: file not found, division by zero. ● Shown at run time #include<iostream> using namespace std; void main() { int x = 10; int y = 0; cout << x / y; // division by zero }
  • 14. Logical Errors ● These errors cause a program to generate wrong output. ● Maybe your understanding of the underlying program is flawed; maybe you didn’t write what you thought you wrote. Example: wrong formula for Simple Interest. #include<iostream> using namespace std; void main() { int principal = 1000, rate = 2, time = 1 ; int si = principal * rate * 100 / time; // wrong formula cout << si; }
  • 15. Find errors in the following code snippets int main() { int i = 10; j = 5; int modResult = 0; int divResult = 0; modResult = i % j; cout << modResult << " "; divResult = i / modResult; cout << divResult; return 0; }
  • 16. #include<iostream> using namespace std; void main() { cout << 'C++ Programming questions'; int x = 10, y = 5; int ans = x / (y - y); cout << ans return 0; } #include<iostream> using namespace std; void main() { a,b,s int; d float; cout<<"The end of the program"; return 0; }
  • 17. Wisdom of the Wizards Programs must be written for people to read, and only incidentally for machines to execute. Any fool can write code that a computer can understand. Good programmers write code that humans can understand. Minimise time needed by someone else to understand a piece of your code. Remember that someone else may be you, six months after writing the code.
  • 18. Naming is 90% of Programming ● Separate names for readability with underscores or hyphens or capitalization ● Coding standards apply ● Use is and has as boolean name prefixes ● Avoid negative names ● Add necessary detail in name: response_time_ms ● Avoid ambiguity: bool read_file, no_items
  • 19. Practice Questions Question 1 Write a program to input marks of five subjects and calculate average. Question 2 Write a program to enter temperature in degree fahrenheit and change it into degree celcius. Question 3 Write a program to enter three numbers and find greatest number using ternary operators. Question 4 Write a program to enter two numbers and swap their values.