SlideShare a Scribd company logo
Object Oriented Programming: 8
Basics of C++ Programming
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2
The Basics of a C++ Program
• Function: collection of statements; when
executed, accomplishes something
– May be predefined or standard
• Syntax: rules that specify which statements
(instructions) are legal
• Programming language: a set of rules,
symbols, and special words
• Semantic rule: meaning of the instruction
3
Comments
• Comments are for the reader, not the compiler
• Two types:
– Single line
// This is a C++ program. It prints the sentence:
// Welcome to C++ Programming.
– Multiple line
/*
You can include comments that can
occupy several lines.
*/
4
Special Symbols
• Special symbols
+
-
*
/
.
;
?
,
<=
!=
==
>=
5
Reserved Words (Keywords)
• Reserved words, keywords, or word symbols
– Include:
• int
• float
• double
• char
• const
• void
• return
6
Identifiers
• Consist of letters, digits, and the underscore
character (_)
• Must begin with a letter or underscore
• C++ is case sensitive
– NUMBER is not the same as number
• Two predefined identifiers are cout and cin
• Unlike reserved words, predefined identifiers
may be redefined, but it is not a good idea
7
Identifiers (continued)
• The following are legal identifiers in C++:
– first
– conversion
– payRate
8
Whitespaces
• Every C++ program contains whitespaces
– Include blanks, tabs, and newline characters
• Used to separate special symbols, reserved
words, and identifiers
• Proper utilization of whitespaces is important
– Can be used to make the program readable
9
Data Types
• Data type: set of values together with a set of
operations
• C++ data types fall into three categories:
10
Simple Data Types
• Three categories of simple data
– Integral: integers (numbers without a decimal)
– Floating-point: decimal numbers
– Enumeration type: user-defined data type
11
Simple Data Types (continued)
• Integral data types are further classified into
nine categories:
12
Simple Data Types (continued)
• Different compilers may allow different ranges
of values
13
int Data Type
• Examples:
-6728
0
78
+763
• Positive integers do not need a + sign
• No commas are used within an integer
– Commas are used for separating items in a list
14
bool Data Type
• bool type
– Two values: true and false
– Manipulate logical (Boolean) expressions
• true and false are called logical values
• bool, true, and false are reserved words
15
char Data Type
• The smallest integral data type
• Used for characters: letters, digits, and special
symbols
• Each character is enclosed in single quotes
– 'A', 'a', '0', '*', '+', '$', '&'
• A blank space is a character and is written '
', with a space left between the single quotes
16
• C++ uses scientific notation to represent real
numbers (floating-point notation)
Floating-Point Data Types
17
Floating-Point Data Types (continued)
– float: represents any real number
• Range: -3.4E+38 to 3.4E+38 (four bytes)
– double: represents any real number
• Range: -1.7E+308 to 1.7E+308 (eight bytes)
– On most newer compilers, data types double
and long double are same
18
Floating-Point Data Types (continued)
• Maximum number of significant digits
(decimal places) for float values is 6 or 7
• Maximum number of significant digits for
double is 15
• Precision: maximum number of significant
digits
– Float values are called single precision
– Double values are called double precision
19
Arithmetic Operators and Operator
Precedence
• C++ arithmetic operators:
– + addition
– - subtraction
– * multiplication
– / division
– % modulus operator
• +, -, *, and / can be used with integral and
floating-point data types
• Operators can be unary or binary
20
Order of Precedence
• All operations inside of () are evaluated first
• *, /, and % are at the same level of
precedence and are evaluated next
• + and – have the same level of precedence
and are evaluated last
• When operators are on the same level
– Performed from left to right (associativity)
• 3 * 7 - 6 + 2 * 5 / 4 + 6 means
(((3 * 7) – 6) + ((2 * 5) / 4 )) + 6
Assignment
• Discuss in detail the rules related to Identifiers
in C++
• What are the data types available in C++

More Related Content

What's hot (19)

PPTX
Decimal, Binary, Octal, And Hexadecimal number systems.
AOUN ABBAS
 
PPTX
Constant, variables, data types
Pratik Devmurari
 
PPTX
Object oriented programming 13 input stream and devices in cpp
Vaibhav Khanna
 
PPTX
Gates and Flip flop
hamza munir
 
PPTX
Introduction to binary number system
Vikas Dongre
 
PPTX
Number Systems
Gaditek
 
PPTX
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
PPTX
Object oriented programming 11 preprocessor directives and program structure
Vaibhav Khanna
 
PPTX
C programming Tutorial Session 1
Muhammad Ehtisham Siddiqui
 
PPTX
Numeric Data Types & Strings
Abhinav Porwal
 
PDF
2 expressions (ppt-2) in C++
Kuntal Bhowmick
 
PPT
Computer Programming
Burhan Fakhar
 
PPT
constants, variables and datatypes in C
Sahithi Naraparaju
 
PPTX
Data types
Zahid Hussain
 
PPTX
Data types
Syed Umair
 
PDF
Cp presentation
MeetaPrajapati
 
PDF
Numbersystem 130621192712-phpapp02
muhammadsarab
 
PDF
Computerarchitecture by csa
bathala sudhakar
 
PPTX
Programming construction tools
sunilchute1
 
Decimal, Binary, Octal, And Hexadecimal number systems.
AOUN ABBAS
 
Constant, variables, data types
Pratik Devmurari
 
Object oriented programming 13 input stream and devices in cpp
Vaibhav Khanna
 
Gates and Flip flop
hamza munir
 
Introduction to binary number system
Vikas Dongre
 
Number Systems
Gaditek
 
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Object oriented programming 11 preprocessor directives and program structure
Vaibhav Khanna
 
C programming Tutorial Session 1
Muhammad Ehtisham Siddiqui
 
Numeric Data Types & Strings
Abhinav Porwal
 
2 expressions (ppt-2) in C++
Kuntal Bhowmick
 
Computer Programming
Burhan Fakhar
 
constants, variables and datatypes in C
Sahithi Naraparaju
 
Data types
Zahid Hussain
 
Data types
Syed Umair
 
Cp presentation
MeetaPrajapati
 
Numbersystem 130621192712-phpapp02
muhammadsarab
 
Computerarchitecture by csa
bathala sudhakar
 
Programming construction tools
sunilchute1
 

Similar to Object oriented programming 8 basics of c++ programming (20)

PPT
Basics of c++ Programming Language
Ahmad Idrees
 
PPTX
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
PPT
PPT slide_chapter 02 Basic element of C++.ppt
masadjie
 
PPT
C++.ppt
shweta210
 
PPT
9781285852744 ppt ch02
Terry Yoast
 
PPT
Basic elements of java
Ahmad Idrees
 
PPT
programming week 2.ppt
FatimaZafar68
 
PPTX
Lecture 2 variables
Tony Apreku
 
PPTX
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
PDF
5 conceptos progamacion2-tema4
Elba Sepúlveda
 
PDF
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
PDF
INTRODUCTION TO C PROGRAMMING in basic c language
GOKULKANNANMMECLECTC
 
PPTX
Data structure Unit-I Part A
SSN College of Engineering, Kalavakkam
 
PPTX
1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx
naagin12300
 
PPTX
Lecture 2
marvellous2
 
PPTX
C programming language
Abin Rimal
 
PPTX
1.4 Work with data types and variables, numeric data, string data.pptx
VGaneshKarthikeyan
 
PPTX
B.sc CSIT 2nd semester C++ Unit2
Tekendra Nath Yogi
 
Basics of c++ Programming Language
Ahmad Idrees
 
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
PPT slide_chapter 02 Basic element of C++.ppt
masadjie
 
C++.ppt
shweta210
 
9781285852744 ppt ch02
Terry Yoast
 
Basic elements of java
Ahmad Idrees
 
programming week 2.ppt
FatimaZafar68
 
Lecture 2 variables
Tony Apreku
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
5 conceptos progamacion2-tema4
Elba Sepúlveda
 
Module_1_Introduction-to-Problem-Solving.pdf
MaheshKini3
 
INTRODUCTION TO C PROGRAMMING in basic c language
GOKULKANNANMMECLECTC
 
Data structure Unit-I Part A
SSN College of Engineering, Kalavakkam
 
1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx
naagin12300
 
Lecture 2
marvellous2
 
C programming language
Abin Rimal
 
1.4 Work with data types and variables, numeric data, string data.pptx
VGaneshKarthikeyan
 
B.sc CSIT 2nd semester C++ Unit2
Tekendra Nath Yogi
 
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
Vaibhav Khanna
 
PPTX
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
PPTX
Information and network security 45 digital signature standard
Vaibhav Khanna
 
PPTX
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
PPTX
Information and network security 43 digital signatures
Vaibhav Khanna
 
PPTX
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
PPTX
Information and network security 41 message authentication code
Vaibhav Khanna
 
PPTX
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
PPTX
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
PPTX
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
PPTX
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
PPTX
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
PPTX
Information and network security 34 primality
Vaibhav Khanna
 
PPTX
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
PPTX
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
PPTX
Information and network security 31 public key cryptography
Vaibhav Khanna
 
PPTX
Information and network security 30 random numbers
Vaibhav Khanna
 
PPTX
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
PPTX
Information and network security 28 blowfish
Vaibhav Khanna
 
PPTX
Information and network security 27 triple des
Vaibhav Khanna
 
Information and network security 47 authentication applications
Vaibhav Khanna
 
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
Information and network security 45 digital signature standard
Vaibhav Khanna
 
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
Information and network security 43 digital signatures
Vaibhav Khanna
 
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
Information and network security 41 message authentication code
Vaibhav Khanna
 
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
Information and network security 34 primality
Vaibhav Khanna
 
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
Information and network security 31 public key cryptography
Vaibhav Khanna
 
Information and network security 30 random numbers
Vaibhav Khanna
 
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
Information and network security 28 blowfish
Vaibhav Khanna
 
Information and network security 27 triple des
Vaibhav Khanna
 
Ad

Recently uploaded (20)

PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PPTX
For my supp to finally picking supp that work
necas19388
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
For my supp to finally picking supp that work
necas19388
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
Dealing with JSON in the relational world
Andres Almiray
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
Rewards and Recognition (2).pdf
ethan Talor
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 

Object oriented programming 8 basics of c++ programming

  • 1. Object Oriented Programming: 8 Basics of C++ Programming Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 2 The Basics of a C++ Program • Function: collection of statements; when executed, accomplishes something – May be predefined or standard • Syntax: rules that specify which statements (instructions) are legal • Programming language: a set of rules, symbols, and special words • Semantic rule: meaning of the instruction
  • 3. 3 Comments • Comments are for the reader, not the compiler • Two types: – Single line // This is a C++ program. It prints the sentence: // Welcome to C++ Programming. – Multiple line /* You can include comments that can occupy several lines. */
  • 4. 4 Special Symbols • Special symbols + - * / . ; ? , <= != == >=
  • 5. 5 Reserved Words (Keywords) • Reserved words, keywords, or word symbols – Include: • int • float • double • char • const • void • return
  • 6. 6 Identifiers • Consist of letters, digits, and the underscore character (_) • Must begin with a letter or underscore • C++ is case sensitive – NUMBER is not the same as number • Two predefined identifiers are cout and cin • Unlike reserved words, predefined identifiers may be redefined, but it is not a good idea
  • 7. 7 Identifiers (continued) • The following are legal identifiers in C++: – first – conversion – payRate
  • 8. 8 Whitespaces • Every C++ program contains whitespaces – Include blanks, tabs, and newline characters • Used to separate special symbols, reserved words, and identifiers • Proper utilization of whitespaces is important – Can be used to make the program readable
  • 9. 9 Data Types • Data type: set of values together with a set of operations • C++ data types fall into three categories:
  • 10. 10 Simple Data Types • Three categories of simple data – Integral: integers (numbers without a decimal) – Floating-point: decimal numbers – Enumeration type: user-defined data type
  • 11. 11 Simple Data Types (continued) • Integral data types are further classified into nine categories:
  • 12. 12 Simple Data Types (continued) • Different compilers may allow different ranges of values
  • 13. 13 int Data Type • Examples: -6728 0 78 +763 • Positive integers do not need a + sign • No commas are used within an integer – Commas are used for separating items in a list
  • 14. 14 bool Data Type • bool type – Two values: true and false – Manipulate logical (Boolean) expressions • true and false are called logical values • bool, true, and false are reserved words
  • 15. 15 char Data Type • The smallest integral data type • Used for characters: letters, digits, and special symbols • Each character is enclosed in single quotes – 'A', 'a', '0', '*', '+', '$', '&' • A blank space is a character and is written ' ', with a space left between the single quotes
  • 16. 16 • C++ uses scientific notation to represent real numbers (floating-point notation) Floating-Point Data Types
  • 17. 17 Floating-Point Data Types (continued) – float: represents any real number • Range: -3.4E+38 to 3.4E+38 (four bytes) – double: represents any real number • Range: -1.7E+308 to 1.7E+308 (eight bytes) – On most newer compilers, data types double and long double are same
  • 18. 18 Floating-Point Data Types (continued) • Maximum number of significant digits (decimal places) for float values is 6 or 7 • Maximum number of significant digits for double is 15 • Precision: maximum number of significant digits – Float values are called single precision – Double values are called double precision
  • 19. 19 Arithmetic Operators and Operator Precedence • C++ arithmetic operators: – + addition – - subtraction – * multiplication – / division – % modulus operator • +, -, *, and / can be used with integral and floating-point data types • Operators can be unary or binary
  • 20. 20 Order of Precedence • All operations inside of () are evaluated first • *, /, and % are at the same level of precedence and are evaluated next • + and – have the same level of precedence and are evaluated last • When operators are on the same level – Performed from left to right (associativity) • 3 * 7 - 6 + 2 * 5 / 4 + 6 means (((3 * 7) – 6) + ((2 * 5) / 4 )) + 6
  • 21. Assignment • Discuss in detail the rules related to Identifiers in C++ • What are the data types available in C++