CONSTANTS IN C++ TRB CSI › Programming with C++ › constants

CONSTANTS IN C++

Constant என்பது program execution நடக்கும் போது அதன் value change ஆகாமல் இருக்கும் fixed value. Simple definition: A constant is a fixed value that does not change during program execution.

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

CONSTANTS IN C++…

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

Constant என்பது program execution நடக்கும் போது அதன் value change ஆகாமல் இ……

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

const int MAX = 100; இங்கு: MAX → Constant identifier 10……

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

Variable என்றால் value change ஆகலாம். int age = 20; age = 21; இங்கு age value: 20 → 21 என்று change ஆகிறது……

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

Mathematics-ல்: π = 3.14159... π-ன் value fixed. அத……

Premium This card is part of the premium lesson. Unlock
Explanation
Why constants are needed

Program-ல் சில values change ஆகக்கூடாது. PI Number of days in a week Maximum marks Tax rate Conversion value ……

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

return 0; }…

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

const int MAX_MARK = 100; const C++ keyword. Compiler-க்கு: இந்த variable-ன் value later change செய்யக……

Premium This card is part of the premium lesson. Unlock
Explanation
What happens if we change it?

const int MAX = 100; MAX = 200; இது invalid. Comp……

Premium This card is part of the premium lesson. Unlock
Comparison
Variable vs constant

Variable int x = 10; x = 20; V……

Premium This card is part of the premium lesson. Unlock
Explanation
Types of constant values / literals

C++-ல் fixed values பல types-ல் இருக்கலாம். Main types: Int……

Premium This card is part of the premium lesson. Unlock

INTEGER CONSTANT

Explanation

Decimal point இல்லாத whole number values. Examples: 10 100 ……

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

const int DAYS = 7; const int MONTHS = 1……

Premium This card is part of the premium lesson. Unlock

FLOATING-POINT CONSTANT

Real Life Example

Decimal point கொண்ட numbers. ……

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

const float PI = 3.14;…

Premium This card is part of the premium lesson. Unlock

3.14 → Floating-point literal.

Explanation
Double constant

const double PI = 3.14159265; Her……

Premium This card is part of the premium lesson. Unlock

CHARACTER CONSTANT

Explanation

Single character-ஐ single quotation marks ' ' குள் எழு……

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

Character: 'A' Single quotes. S……

Premium This card is part of the premium lesson. Unlock

STRING LITERAL

Important

Multiple characters-ஐ double quotation mar……

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

string name = "Ravi"; "Ravi" → String lite……

Premium This card is part of the premium lesson. Unlock

BOOLEAN LITERALS

Explanation

C++-ல் Boolean literals இரண்டு: tru……

Premium This card is part of the premium lesson. Unlock
Comparison
Literal vs const constant

இந்த concept மிகவும் important. Consider: const int MAX = 100; இதில்: const → Keyword MAX → Identifier 100 → ……

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

int x = 50; 50 ஒரு integer literal. ஆனால் x constant அல்ல. Beca……

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

Normally const variable declare செய்யும்போதே initialize செய்வது வேண்டும். Correct: co……

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

Declare constant | v const int MAX = 100; | v Value ……

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

double radius = 5; double are……

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

return 0; }…

Premium This card is part of the premium lesson. Unlock

approximately.…

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

const double PI = 3.14159; PI constant. double ra……

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

Area = πr² So: 3.14159 × 5 × ……

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

const int MAX = 100; int mark……

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

Fixed. Step 2:…

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

Variable. Step 3: Program pri……

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

compiler rejects it.…

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

Older C/C++ code-ல் #define மூலம் symbolic constants உருவாக்கப்படலாம்……

Premium This card is part of the premium lesson. Unlock
Comparison
Const vs #define

Modern C++-ல் பொதுவாக typed c……

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

const double PI = 3.14; compa……

Premium This card is part of the premium lesson. Unlock
Comparison
Difference
Important
Constexpr - important advanced point

Modern C++-ல்: constexpr int SIZE = 10; constexpr என்பது ……

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

constexpr int DAYS = 7; For basics: const → value cannot be modified through that const obj……

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

Constants-க்கு uppercase names பயன்படுத்துவது common convention. const int MAX_SIZE = 100; const ……

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

const int MAX = 100; MAX = 200;……

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

const int MAX; Local const object-க்கு in……

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

Character மற்றும் string confuse செய்வது. Wr……

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

Constant name uppercase-ல் இருக்க வேண்டும் என்பது compulsory ……

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

Consider: const int x = 10; இதை token-wise பார்க்கலாம்: const → Keyword int → Keyword / type specifie……

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

const int A = 10; const int B……

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

C-ன் value initialization முட……

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

const என்பது ஒரு type qualifi……

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

const int x = 10; இதில் const compi……

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

CONST = CONSTANT = CANNOT CHANGE V……

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

int x = 10; Change possible. ……

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

What is a constant in C++? Answer: A constant is a fixed v……

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

const int x = 10; Which state……

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

Difference between constant and literal? Consider: const int MAX = 100; MAX → named constant ……

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

Which keyword is commonly use……

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

In: const int MAX = 100; 100 ……

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

In: const int MAX = 100; MAX ……

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

Which is a floating-point lit……

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

Which is a character literal?…

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

Which are Boolean literals in……

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

What happens here? const int ……

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

Identify each part: const double RATE = 5.5; Answer: cons……

Premium This card is part of the premium lesson. Unlock

5.5 → Floating-point literal

; → Punctuator…

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

Which can be changed? int x = 10; const int y = 20; Answer:……

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

Constant A fixed value that d……

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

const data_type name = value; const int MAX = 100; Breakdown: const → K……

Premium This card is part of the premium lesson. Unlock

3.14 → Floating point

'A' → Character "Hello" → String true → Boolean Most important exam difference: int x = 10; x ……

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