SlideShare a Scribd company logo
Lecture 1
Chapter # 2
C++ Programming Basics
Lecture # 1
Instructor: Engr. Afshan Asim
Objectives
 C++ Program Structure.
 Whitespaces
 Comments
 Escape Sequences
 Data Types & Variables
 Unsigned Types
Lecture 1
Compiler
Compiler is a tool that is used to
convert/translate human like language
into machine language
Simple C++ Program
#include<iostream>
using namespace std;
void main()
{
cout<<“This is my 1st
C++ program”;
system(“pause”);
}
Whitespace
#include<iostream>
using
namespace std;
void main() { cout
<<
“This is my 1st
C++ program”;
system(“pause”);
}
Comments
Single Line Comment
//This is single line comment
Or
//This is single
//Line comment
Multi Line Comment or Block Comment
/*This is
Multi line
Comment*/
Comments Contd…
//demonstrates Comments
#include<iostream>
using namespace std;
//main function
void main()
{
cout<<“This is my 1st
C++ program”;
system(“pause”);
}/* end of
program*/
Common Escape Sequences
Escape
Sequence
Character
a Beep
b Backspace
f Form feed
n New line
r Return
t Tab
 Backslash
’ Single quotation mark
” Double quotation marks
xdd Hexadecimal Notations
Escape Sequences (Contd…)
• cout<<“This isb my first C++ program”;
This i my first C++ program
• cout<<“This isn my first C++ program”;
This is
my first C++ program
• cout<<“This is my first r C++ program”;
C++ programirst
• cout<<“This ist my first C++ program”;
This is my first C++ program
Escape Sequences (Contd…)
• cout<<“This is my first C++ program”;
This is  my first C++ program
• cout<<“This is’ my first C++ ’ program”;
This is ‘ my first C++ ‘ program
• cout<<“”This is my first C++ program””;
“This is my first C++ program”
• cout<<“x128”;
<
Integer Variables
Type Bits Range Syntax
int (32 bit
system)
32 bits -2,147,483,648

2,147,483,647
int var1;
int (16 bit
system)
16 bits -32,768 
32767
int var1;
long 32 bits -2,147,483,648

2,147,483,647
long int var1;
or
long var1;
short 16 bits -32,768 
32767
short var1;
Integer Variables
//demonstrates integer variables
#include<iostream>
using namespace std;
void main()
{
int var1; //define var1
int var2=20; //20 is integer constant
var1=var2+10;
cout<<“value of var1=”<<var1;
system(“pause”);
}/* end of program*/
Character Variables & Constants
• Character Variable
Range: -128 127
Memory: 1 byte (8 bits)
• Character Constant
Enclosed in single quotation mark
e.g. ‘A’ , ‘c’ , ‘2’
Character Variables & Constants Contd…
//Demonstrates Character variables
#include<iostream>
using namespace std;
void main()
{
char ch1=88;
char ch2=‘A’; //’A’ is character constant
cout<<ch1<<“n”<<ch2;
ch1++;
cout<<ch1;
system(“pause”);
}
Floating Point Types
Type Bits Range Syntax
float 4 bytes float var;
double 8 bytes double var;
long double 10 bytes long double
var;
Floating Point Types (Contd…)
//Floating point types
#include<iostream>
using namespace std;
void main()
{
float f=312.4F; //type float constant with letter F
double d=2.34E5;
long double l=2.345E10L; //type float constant with letter
L
cout<<“n Type float:”<<f<<“n Type double”<<d<<“n
Type long double”<<l;
system(“pause”);
}
Type bool
• 1 bit of storage…
• Only two values.. 0 and 1
//Type bool
#include<iostream>
using namespace std;
void main()
{
bool b,b1;
b=5>3; //result is 1
b1=3>5; //result is 0
cout<<“b=“<<b<<“b1=“<<b1;
system(“pause”);
}
unsigned Data Types
Type Low High Syntax
unsigned char 0 255 unsigned char
var;
unsigned short 0 65,535 unsigned short
var;
unsigned int 0 4,294,967,295 unsigned int var;
unsigned long 0 4,294,967,295 unsigned long
var;
Lecture 1

More Related Content

PPTX
Planet of the AOPs
PPT
C++ programming
PPT
Fpga 06-data-types-system-tasks-compiler-directives
PDF
CODEsign 2015
PPT
Verilog Lecture4 2014
PDF
04 sequentialbasics 1
PPT
Verilog Lecture2 thhts
PDF
Heading for a Record: Chromium, the 5th Check
Planet of the AOPs
C++ programming
Fpga 06-data-types-system-tasks-compiler-directives
CODEsign 2015
Verilog Lecture4 2014
04 sequentialbasics 1
Verilog Lecture2 thhts
Heading for a Record: Chromium, the 5th Check

What's hot (19)

PPT
C++ programming
PPTX
Command line arguments
PDF
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
PDF
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
PPT
Functions
PDF
Notes: Verilog Part 4- Behavioural Modelling
DOC
H U F M A N Algorithm Index
PPT
Command line arguments.21
PDF
Delays in verilog
DOC
H U F F M A N Algorithm
DOC
H U F F M A N Algorithm Class
PPT
Coding verilog
DOC
Lex tool manual
PPT
C++ control loops
PPTX
Python Basics
PPTX
Lesson 7 io statements
PPT
Lexyacc
DOCX
PPT
Loader
C++ programming
Command line arguments
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Functions
Notes: Verilog Part 4- Behavioural Modelling
H U F M A N Algorithm Index
Command line arguments.21
Delays in verilog
H U F F M A N Algorithm
H U F F M A N Algorithm Class
Coding verilog
Lex tool manual
C++ control loops
Python Basics
Lesson 7 io statements
Lexyacc
Loader
Ad

Viewers also liked (8)

PPT
c++ Lecture 1
PPT
c++ Lecture 2
PDF
Lecture 4
PDF
c++ Lecture 4
DOC
AnµLisis De La Pel÷Cula Una Mente Brillante
PPT
basic c++(1)
PPT
c++ Lecture 3
PPTX
STEP(Solar Technology for Energy Production)
c++ Lecture 1
c++ Lecture 2
Lecture 4
c++ Lecture 4
AnµLisis De La Pel÷Cula Una Mente Brillante
basic c++(1)
c++ Lecture 3
STEP(Solar Technology for Energy Production)
Ad

Similar to Lecture 1 (20)

PPTX
C++ AND CATEGORIES OF SOFTWARE
PPT
Fp201 unit2 1
PPTX
C++ basics
PPTX
Presentation c++
PPTX
Intro in understanding to C programming .pptx
PPTX
Intro in understanding to C programming .pptx
PPT
7512635.ppt
PDF
Prog1-L1.pdf
PDF
C++ L01-Variables
PPTX
CP 04.pptx
PDF
C_and_C++_notes.pdf
PPTX
POLITEKNIK MALAYSIA
PPTX
C++ Functions
PPTX
C++ programming language basic to advance level
DOCX
System programmin practical file
PPT
C Programming
PPTX
Programming using c++ tool
PPTX
Introduction Of C++
PPTX
Basics of c Nisarg Patel
C++ AND CATEGORIES OF SOFTWARE
Fp201 unit2 1
C++ basics
Presentation c++
Intro in understanding to C programming .pptx
Intro in understanding to C programming .pptx
7512635.ppt
Prog1-L1.pdf
C++ L01-Variables
CP 04.pptx
C_and_C++_notes.pdf
POLITEKNIK MALAYSIA
C++ Functions
C++ programming language basic to advance level
System programmin practical file
C Programming
Programming using c++ tool
Introduction Of C++
Basics of c Nisarg Patel

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
The AUB Centre for AI in Media Proposal.docx
sap open course for s4hana steps from ECC to s4
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx

Lecture 1

  • 2. Chapter # 2 C++ Programming Basics Lecture # 1 Instructor: Engr. Afshan Asim
  • 3. Objectives  C++ Program Structure.  Whitespaces  Comments  Escape Sequences  Data Types & Variables  Unsigned Types
  • 5. Compiler Compiler is a tool that is used to convert/translate human like language into machine language
  • 6. Simple C++ Program #include<iostream> using namespace std; void main() { cout<<“This is my 1st C++ program”; system(“pause”); }
  • 7. Whitespace #include<iostream> using namespace std; void main() { cout << “This is my 1st C++ program”; system(“pause”); }
  • 8. Comments Single Line Comment //This is single line comment Or //This is single //Line comment Multi Line Comment or Block Comment /*This is Multi line Comment*/
  • 9. Comments Contd… //demonstrates Comments #include<iostream> using namespace std; //main function void main() { cout<<“This is my 1st C++ program”; system(“pause”); }/* end of program*/
  • 10. Common Escape Sequences Escape Sequence Character a Beep b Backspace f Form feed n New line r Return t Tab Backslash ’ Single quotation mark ” Double quotation marks xdd Hexadecimal Notations
  • 11. Escape Sequences (Contd…) • cout<<“This isb my first C++ program”; This i my first C++ program • cout<<“This isn my first C++ program”; This is my first C++ program • cout<<“This is my first r C++ program”; C++ programirst • cout<<“This ist my first C++ program”; This is my first C++ program
  • 12. Escape Sequences (Contd…) • cout<<“This is my first C++ program”; This is my first C++ program • cout<<“This is’ my first C++ ’ program”; This is ‘ my first C++ ‘ program • cout<<“”This is my first C++ program””; “This is my first C++ program” • cout<<“x128”; <
  • 13. Integer Variables Type Bits Range Syntax int (32 bit system) 32 bits -2,147,483,648  2,147,483,647 int var1; int (16 bit system) 16 bits -32,768  32767 int var1; long 32 bits -2,147,483,648  2,147,483,647 long int var1; or long var1; short 16 bits -32,768  32767 short var1;
  • 14. Integer Variables //demonstrates integer variables #include<iostream> using namespace std; void main() { int var1; //define var1 int var2=20; //20 is integer constant var1=var2+10; cout<<“value of var1=”<<var1; system(“pause”); }/* end of program*/
  • 15. Character Variables & Constants • Character Variable Range: -128 127 Memory: 1 byte (8 bits) • Character Constant Enclosed in single quotation mark e.g. ‘A’ , ‘c’ , ‘2’
  • 16. Character Variables & Constants Contd… //Demonstrates Character variables #include<iostream> using namespace std; void main() { char ch1=88; char ch2=‘A’; //’A’ is character constant cout<<ch1<<“n”<<ch2; ch1++; cout<<ch1; system(“pause”); }
  • 17. Floating Point Types Type Bits Range Syntax float 4 bytes float var; double 8 bytes double var; long double 10 bytes long double var;
  • 18. Floating Point Types (Contd…) //Floating point types #include<iostream> using namespace std; void main() { float f=312.4F; //type float constant with letter F double d=2.34E5; long double l=2.345E10L; //type float constant with letter L cout<<“n Type float:”<<f<<“n Type double”<<d<<“n Type long double”<<l; system(“pause”); }
  • 19. Type bool • 1 bit of storage… • Only two values.. 0 and 1 //Type bool #include<iostream> using namespace std; void main() { bool b,b1; b=5>3; //result is 1 b1=3>5; //result is 0 cout<<“b=“<<b<<“b1=“<<b1; system(“pause”); }
  • 20. unsigned Data Types Type Low High Syntax unsigned char 0 255 unsigned char var; unsigned short 0 65,535 unsigned short var; unsigned int 0 4,294,967,295 unsigned int var; unsigned long 0 4,294,967,295 unsigned long var;