0% found this document useful (0 votes)
2 views12 pages

cpp3

The document outlines C++ primary data types, including int, char, float, double, and void, detailing their uses, memory sizes, and examples. It also discusses type modifiers that can alter the size or range of base data types, as well as the declaration of variables and constants in C++. Additionally, it categorizes constants into integer, floating-point, character, and string constants with examples for each.

Uploaded by

outlooksinet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

cpp3

The document outlines C++ primary data types, including int, char, float, double, and void, detailing their uses, memory sizes, and examples. It also discusses type modifiers that can alter the size or range of base data types, as well as the declaration of variables and constants in C++. Additionally, it categorizes constants into integer, floating-point, character, and string constants with examples for each.

Uploaded by

outlooksinet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

C++ Primary Data types

SESSION 3
Data Types
Data types specify the type of data a

variable can hold.


Helps the compiler allocate memory and

interpret values.

Categories of Data Types:


Primary (Fundamental)

Derived

User-defined
www.sinet.in 2
Primary (Fundamental) Data Types
1. int – Integer
 Used for: Storing whole numbers without any decimal

point.
 Memory size: Typically 4 bytes (can store -

2,147,483,648 to 2,147,483,647)

2. char – Character
 Used for: Storing a single character.

 Memory size: 1 byte (stores ASCII characters)

 Stored using: Single quotes ' '


www.sinet.in 3
.3. float – Floating Point
 Used for: Storing decimal numbers (single precision).

 Memory size: 4 bytes

4. double – Double Precision Floating Point


 Used for: Storing larger and more precise decimal

numbers.
 Memory size: 8 bytes

5. void – No Value
 Used for: Indicating no data type.

 Commonly used in:

 Functions that don’t return any value.


www.sinet.in 4
.
Data Type Description Example Value Memory Size

int Whole numbers 42, -5 4 bytes

Single
char 'A', '9' 1 byte
characters
Decimal
float numbers (less 3.14f, -0.5f 4 bytes
precise)
Decimal (more
double 6.022e23 8 bytes
precise)

No value (used
void void 0 bytes
in functions)

www.sinet.in 5
Type Modifiers
Type modifiers change the size or range of
the base data types like int and char.
🔸 Available Modifiers:
short
long
signed
unsigned
You can combine them with primary types like
int and char.

www.sinet.in 6
.
🔸 short int
 Smaller range than int.

 Typically uses 2 bytes.

🔸 long int
 Larger range than int.

 Typically uses 4 to 8 bytes depending on the system.

🔸 unsigned int
 Only stores non-negative numbers.

 Doubles the upper limit of positive values.

🔸 signed int
 Default modifier (can store both positive and negative values).
www.sinet.in 7
Declaring Variables
🔸 What is a Variable?
A named storage location that holds data
which can be changed during program
execution.
Syntax:
data_type variable_name;
Eg: int age = 25;
www.sinet.in 8
Constants
🔸 What is a Constant?

A value that cannot change during program execution.

🔸 How to Define a Constant:


 Using const keyword:

const float PI = 3.14;


 Using #define directive:

#define MAX_SCORE 100

www.sinet.in 9
Types of Constants
1. Integer Constants
Whole numbers (positive or negative).

No decimal.

Eg: const int DAYS = 7;

2. Floating-Point Constants
Numbers with decimal point.

Eg: const float PI = 3.1415;


www.sinet.in 10
.3. Character Constants
A character in single quotes.

Eg: const char GRADE = 'A';

4. String Constants
A sequence of characters inside double

quotes.
Eg: const char message[] = "Welcome to C++!";
www.sinet.in 11
END

www.sinet.in 12

You might also like