SlideShare una empresa de Scribd logo
1 de 21
Chapter # 2
C++ Programming Basics
Lecture # 1
Instructor: Engr. Afshan Asim
Objectives
 C++ Program Structure.
 Whitespaces
 Comments
 Escape Sequences
 Data Types & Variables
 Unsigned Types
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

Más contenido relacionado

La actualidad más candente

Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Jay Baxi
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsJay Baxi
 
Notes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingNotes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingJay Baxi
 
H U F M A N Algorithm Index
H U F M A N Algorithm IndexH U F M A N Algorithm Index
H U F M A N Algorithm IndexJade Danial
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21myrajendra
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilogJITU MISTRY
 
H U F F M A N Algorithm
H U F F M A N AlgorithmH U F F M A N Algorithm
H U F F M A N AlgorithmJade Danial
 
H U F F M A N Algorithm Class
H U F F M A N Algorithm ClassH U F F M A N Algorithm Class
H U F F M A N Algorithm ClassJade Danial
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 

La actualidad más candente (19)

C++ programming
C++ programmingC++ programming
C++ programming
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
 
Functions
FunctionsFunctions
Functions
 
Notes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural ModellingNotes: Verilog Part 4- Behavioural Modelling
Notes: Verilog Part 4- Behavioural Modelling
 
H U F M A N Algorithm Index
H U F M A N Algorithm IndexH U F M A N Algorithm Index
H U F M A N Algorithm Index
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
H U F F M A N Algorithm
H U F F M A N AlgorithmH U F F M A N Algorithm
H U F F M A N Algorithm
 
H U F F M A N Algorithm Class
H U F F M A N Algorithm ClassH U F F M A N Algorithm Class
H U F F M A N Algorithm Class
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Lesson 7 io statements
Lesson 7 io statementsLesson 7 io statements
Lesson 7 io statements
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
Hd9
Hd9Hd9
Hd9
 
Loader
LoaderLoader
Loader
 

Destacado

c++ Lecture 1
c++ Lecture 1c++ Lecture 1
c++ Lecture 1sajidpk92
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2sajidpk92
 
c++ Lecture 4
c++ Lecture 4c++ Lecture 4
c++ Lecture 4sajidpk92
 
AnµLisis De La Pel÷Cula Una Mente Brillante
AnµLisis De La Pel÷Cula Una Mente BrillanteAnµLisis De La Pel÷Cula Una Mente Brillante
AnµLisis De La Pel÷Cula Una Mente Brillantetunegocioweb
 
basic c++(1)
basic c++(1)basic c++(1)
basic c++(1)sajidpk92
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3sajidpk92
 
STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)sajidpk92
 

Destacado (8)

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

Similar a Lecture 1

Similar a Lecture 1 (20)

C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
C++ basics
C++ basicsC++ basics
C++ basics
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
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
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
C Programming
C ProgrammingC Programming
C Programming
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 

Último

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Paige Cruz
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 

Último (20)

2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

Lecture 1

  • 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
  • 4.
  • 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;