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

PPT
Data types and Operators
PPTX
PPTX
Constants and variables in c programming
PPT
Mesics lecture 3 c – constants and variables
PPTX
C data type format specifier
PPTX
Constant and variacles in c
PPTX
MAGNITUDE COMPARATOR & DECODER
PPTX
Data Type in C Programming
Data types and Operators
Constants and variables in c programming
Mesics lecture 3 c – constants and variables
C data type format specifier
Constant and variacles in c
MAGNITUDE COMPARATOR & DECODER
Data Type in C Programming

What's hot (19)

PPTX
Decimal, Binary, Octal, And Hexadecimal number systems.
PPTX
Constant, variables, data types
PPTX
Object oriented programming 13 input stream and devices in cpp
PPTX
Gates and Flip flop
PPTX
Introduction to binary number system
PPTX
Number Systems
PPTX
Datatype in c++ unit 3 -topic 2
PPTX
Object oriented programming 11 preprocessor directives and program structure
PPTX
C programming Tutorial Session 1
PPTX
Numeric Data Types & Strings
PDF
2 expressions (ppt-2) in C++
PPT
Computer Programming
PPT
constants, variables and datatypes in C
PPTX
Data types
PPTX
Data types
PDF
Cp presentation
PDF
Numbersystem 130621192712-phpapp02
PDF
Computerarchitecture by csa
PPTX
Programming construction tools
Decimal, Binary, Octal, And Hexadecimal number systems.
Constant, variables, data types
Object oriented programming 13 input stream and devices in cpp
Gates and Flip flop
Introduction to binary number system
Number Systems
Datatype in c++ unit 3 -topic 2
Object oriented programming 11 preprocessor directives and program structure
C programming Tutorial Session 1
Numeric Data Types & Strings
2 expressions (ppt-2) in C++
Computer Programming
constants, variables and datatypes in C
Data types
Data types
Cp presentation
Numbersystem 130621192712-phpapp02
Computerarchitecture by csa
Programming construction tools
Ad

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

PPT
Basics of c++ Programming Language
PPTX
Chap_________________1_Introduction.pptx
PPT
PPT slide_chapter 02 Basic element of C++.ppt
PPT
C++.ppt
PPT
9781285852744 ppt ch02
PPT
Basic elements of java
PPT
programming week 2.ppt
PPTX
Lecture 2 variables
PPTX
BASIC C++ lecture NOTE C++ lecture 3.pptx
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
PDF
5 conceptos progamacion2-tema4
PDF
Module_1_Introduction-to-Problem-Solving.pdf
PDF
INTRODUCTION TO C PROGRAMMING in basic c language
PPTX
Data structure Unit-I Part A
PPTX
1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx
PPTX
Lecture 2
PPTX
C programming language
PDF
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
PPTX
1.4 Work with data types and variables, numeric data, string data.pptx
Basics of c++ Programming Language
Chap_________________1_Introduction.pptx
PPT slide_chapter 02 Basic element of C++.ppt
C++.ppt
9781285852744 ppt ch02
Basic elements of java
programming week 2.ppt
Lecture 2 variables
BASIC C++ lecture NOTE C++ lecture 3.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
5 conceptos progamacion2-tema4
Module_1_Introduction-to-Problem-Solving.pdf
INTRODUCTION TO C PROGRAMMING in basic c language
Data structure Unit-I Part A
1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx
Lecture 2
C programming language
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
1.4 Work with data types and variables, numeric data, string data.pptx
Ad

More from Vaibhav Khanna (20)

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

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
System and Network Administration Chapter 2
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
medical staffing services at VALiNTRY
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
ai tools demonstartion for schools and inter college
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
Transform Your Business with a Software ERP System
Operating system designcfffgfgggggggvggggggggg
Understanding Forklifts - TECH EHS Solution
Reimagine Home Health with the Power of Agentic AI​
System and Network Administration Chapter 2
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
medical staffing services at VALiNTRY
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How Creative Agencies Leverage Project Management Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms I-SECS-1021-03
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Digital Strategies for Manufacturing Companies
ai tools demonstartion for schools and inter college
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction to Artificial Intelligence
Transform Your Business with a Software ERP System

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++