DATA TYPES IN C++ TRB CSI › Programming with C++ › data types

DATA TYPES IN C++

Data Type என்பது ஒரு variable எந்த வகையான data-ஐ store செய்ய வேண்டும் என்பதை compiler-க்கு தெரிவிக்கும் type. Simple definition: A data type specifies what kind of value a variable can store.

Premium — locked Advanced 24 min 150 cards 24 programs 10 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

DATA TYPES IN C++…

Premium This card is part of the premium lesson. Unlock
Definition

Data Type என்பது ஒரு variable எந்த வகையான data-ஐ store செய்ய வேண்டும் என்பத……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int age = 25; இங்கு: int → Data type age → Variable / Identifier ……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Real life-ல் different containers different things-க்கு use செய்வோம். Water bottle → Water Rice bag → Rice Mo……

Premium This card is part of the premium lesson. Unlock
Explanation
Why data type is needed

Consider: int marks = 90; Compiler தெரிந்து கொள்கிறது: marks → Integer value Another example: char grade = 'A……

Premium This card is part of the premium lesson. Unlock
Explanation
Classification of c++ data types

C++ data types broadly: Data Types │ ├── 1. Fundamenta……

Premium This card is part of the premium lesson. Unlock

FUNDAMENTAL / BASIC DATA TYPES

Explanation

Main basic data types: int char float……

Premium This card is part of the premium lesson. Unlock
Definition

int integer numbers store செய்ய பயன்படும். Int……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

int variable_name; int age = ……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Important

int normally whole number. Correct: int marks = 90; But: int value = 10.75; இங்கு dec……

Premium This card is part of the premium lesson. Unlock
Definition

float decimal / fractional nu……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

float price = 25.50f; Other example……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Important
Float important

float single-precision floating-p……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

float x = 3.141592f;…

Premium This card is part of the premium lesson. Unlock
Definition

double decimal values-ஐ float……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

double pi = 3.141592653589793;…

Premium This card is part of the premium lesson. Unlock
Comparison
Float vs double

float a = 3.14f; double b = 3.141592653589793; Simple difference: float → Le……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock

Default cout formatting may n……

Premium This card is part of the premium lesson. Unlock
Definition

char ஒரு single character sto……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

char grade = 'A'; Character single quotes-ல் எழுத வேண்டும். Corre……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Char examples

char grade = 'A'; char symbol……

Premium This card is part of the premium lesson. Unlock
Important

char digit = '5'; இதில் '5' n……

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation
Char memory

char usually occupies: 1 byte C++ standard guarantees: sizeo……

Premium This card is part of the premium lesson. Unlock
Definition

bool logical values store செய……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

bool passed = true;…

Premium This card is part of the premium lesson. Unlock
Explanation

return 0; } Usually output: 1……

Premium This card is part of the premium lesson. Unlock
Explanation
Bool with boolalpha

If we want words: #include using ……

Premium This card is part of the premium lesson. Unlock
Definition

void means: No value / no type o……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

display() function எந்த value……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Void example

#include using namespace std;……

Premium This card is part of the premium lesson. Unlock
Important

This is invalid as a normal object declarat……

Premium This card is part of the premium lesson. Unlock
Explanation
Integer type modifiers

C++ integer types-க்கு modifiers use ……

Premium This card is part of the premium lesson. Unlock
Explanation
Signed

int normally signed by default. signed int x = ……

Premium This card is part of the premium lesson. Unlock
Explanation
Unsigned

unsigned negative values represent செய்ய பயன்படாது. u……

Premium This card is part of the premium lesson. Unlock
Comparison
Signed vs unsigned
Explanation
Example

signed int a = -10; unsigned ……

Premium This card is part of the premium lesson. Unlock
Explanation
Short int

Small integer type. short int……

Premium This card is part of the premium lesson. Unlock
Explanation
Long int

Larger or at least not smaller than int in ran……

Premium This card is part of the premium lesson. Unlock
Explanation
Long long

For still wider integer range……

Premium This card is part of the premium lesson. Unlock
Explanation
Integer type relationship

C++ guarantees at least: short ≤ int ≤ long ≤ long long in ter……

Premium This card is part of the premium lesson. Unlock
Explanation
Common size values

On many modern systems, commo……

Premium This card is part of the premium lesson. Unlock
Important

Except for char being exactly 1 byte by definition, ex……

Premium This card is part of the premium lesson. Unlock
Explanation
Sizeof operator

To find actual size: #include……

Premium This card is part of the premium lesson. Unlock
Output
Possible output

This can vary by system.…

Premium This card is part of the premium lesson. Unlock
Concept
Range concept

Every data type has a range. For a common 32-bit int: -2,147,483,648 to 2,147,483,647 Typical unsign……

Premium This card is part of the premium lesson. Unlock
Explanation
Floating types

C++ floating-point types: flo……

Premium This card is part of the premium lesson. Unlock
Explanation
Long double

Higher or at least no less precision/range than double, depending……

Premium This card is part of the premium lesson. Unlock
Explanation
Literal suffixes

Useful exam point: 10 → int literal 10L……

Premium This card is part of the premium lesson. Unlock

3.14 → double literal

3.14f → float literal 3.14L →……

Premium This card is part of the premium lesson. Unlock
Important
String - important

string is commonly used in C++: string name = "Ravi"; But important tec……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Summary
Fundamental data types summary

int → Integer float → Decimal double → Higher pr……

Premium This card is part of the premium lesson. Unlock

DERIVED DATA TYPES

Summary

Derived data types basic types-லிருந்து உ……

Premium This card is part of the premium lesson. Unlock
Explanation
Array

Same type values-ஐ collection ஆக store செய்கிறது. int marks[……

Premium This card is part of the premium lesson. Unlock
Explanation
Pointer

Another object-ன் memory address-ஐ store செய்கிறது. int ……

Premium This card is part of the premium lesson. Unlock
Explanation
Reference

Existing variable-க்கு another name / alias. int x = 10; int &ref = x;……

Premium This card is part of the premium lesson. Unlock

USER-DEFINED DATA TYPES

Explanation

Programmer உருவாக்கும் types. M……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Student programmer-created type. struct ……

Premium This card is part of the premium lesson. Unlock
Explanation
Union

Same memory area-ஐ multiple members sha……

Premium This card is part of the premium lesson. Unlock
Important

At a given time, the active m……

Premium This card is part of the premium lesson. Unlock
Explanation
Enum

Named integral constants define செய்ய பயன……

Premium This card is part of the premium lesson. Unlock
Explanation
Type alias

We can give another name to a type. Using typedef: ty……

Premium This card is part of the premium lesson. Unlock
Table
Data type classification table
Program
Program - multiple data types
Explanation

return 0; }…

Premium This card is part of the premium lesson. Unlock
Explanation

int age = 25; int → whole number. float height = 5.8f; float → decimal value. double salary = 35000.75; doubl……

Premium This card is part of the premium lesson. Unlock
Explanation
Type conversion

ஒரு data type-லிருந்து another type-……

Premium This card is part of the premium lesson. Unlock
Explanation

This is implicit conversion.…

Premium This card is part of the premium lesson. Unlock
Explanation
Implicit conversion

Compiler automatically convert செய்க……

Premium This card is part of the premium lesson. Unlock
Explanation
Explicit conversion

Programmer manually convert செய்கிறார். Modern C++: ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Important type conversion error

double x = 9.99; int y = x;…

Premium This card is part of the premium lesson. Unlock
Output
Possible result

Not: 10 Integer conversion di……

Premium This card is part of the premium lesson. Unlock
Explanation
Auto data type

Modern C++ supports: auto x = 10; Compiler infers: x → int ……

Premium This card is part of the premium lesson. Unlock
Important
Auto important

auto does not mean variable has no data typ……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

const int MAX = 100; Here: const → ……

Premium This card is part of the premium lesson. Unlock
Real Life Example
Signed and unsigned example

signed int a = -100; unsigned……

Premium This card is part of the premium lesson. Unlock
Remember

signed → Negative + Positive unsi……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

int marks = 90; int → Data type marks → Variable / identifier 90 → Value Do not confuse. [DATA TYPE……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 1

Character quotation Wrong: ch……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 2

Decimal into int int x = 10.9; x……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 3

Using text with char Wrong: char name = 'Ravi'……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 4

Boolean confusion Correct: bool status = true; Not:……

Premium This card is part of the premium lesson. Unlock
Dry Run

Consider: int age = 20; double percentage = 89.75; char grade = 'A'; bool pass = true; Comp……

Premium This card is part of the premium lesson. Unlock
Comparison
[FLOAT vs DOUBLE]
Comparison
[CHAR vs STRING]
Comparison

[INT vs FLOAT] int a = 10; St……

Premium This card is part of the premium lesson. Unlock
Remember

int → Integer float → Decimal double → More preci……

Premium This card is part of the premium lesson. Unlock
Remember

I F D C B V I → int F → float D → double C → char B → ……

Premium This card is part of the premium lesson. Unlock
TRB Point

What is a data type? A data type specifies the type of data……

Premium This card is part of the premium lesson. Unlock
TRB Point
C++ data types

1. Fundamental 2. Derived 3. ……

Premium This card is part of the premium lesson. Unlock
TRB Point

Examples: Fundamental → int, char, float, double, bool ……

Premium This card is part of the premium lesson. Unlock
Interview Point

Is string a primitive/fundamental C++ data type? No. std::s……

Premium This card is part of the premium lesson. Unlock
Interview Point

Is int always 4 bytes? No. int size is implementation-dependent. Many m……

Premium This card is part of the premium lesson. Unlock
Interview Point

Difference between float and double? double normally ……

Premium This card is part of the premium lesson. Unlock
MCQ

Which data type stores intege……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is used for a single ch……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is a valid Boolean valu……

Premium This card is part of the premium lesson. Unlock
MCQ

Which normally provides more ……

Premium This card is part of the premium lesson. Unlock
MCQ

Which type indicates no retur……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is correct?…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is a derived data type?…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is a user-defined type?…

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement is technicall……

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator tells the stor……

Premium This card is part of the premium lesson. Unlock
Practice

Identify the data type: int age = 25; float weight = 65.5f; double pi = 3.141……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 2

Choose suitable type: Student age → int Student grade → c……

Premium This card is part of the premium lesson. Unlock
Summary

C++ Data Type A data type tells the compiler what kind of value a variable can store. Main basic types: int →……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program