Constants In C++

Dear Students, aaj ke is Lecture me hum janege Constants In C++ ke bare main. Yani ke c language main constants kaise define karte hai. Or sath me constant kya hote hai. Constants ke definition or types of constants aadi se related ye sare topic ham Constants In C++ me cover karege.

Lectures Covering Topics

  • Introduction To Constants In C++ In Hindi
  • Definition Of Constants In C++ In Hindi
  • Types Of Constants In C++ In Hindi
  • Constants Variables In C++ In Hindi
  • List Of Constants In C++ In Hindi
  • How To Define Constants In C++ In Hindi

Introduction To Constants In C++ In Hindi

Jiasa ki aap log pahle se jante honge ki constant ka matlab sthirank(ruka hua, pahle se hi nirdharit) hota hai. Constants In C++ main agar hum bat kare to yahan par constants ka matlab variables se hai. Constants aise variables hote hai jinki value program main execution ke time par bhi change nahi ki ja sakti hai.

Agar hum program execution me kisi bhi constants variable ka use karte hai. To us variable ki value to vahi rahegi jo program execution se pahle thi. But constants variable ke through kisi other variable ke sath jo bhi execution hui hogi uski value change ho sakti hai.

Jab bhi hum koi bhi constants declare karte hai. Program execution ke time par uski value fixed he rahti hai. Yadi constants ki value change karne ki kosish karte hai to program main error aa jati hai.

Definition Of Constants In C++ In Hindi

Ab hum yhan par constants ki exact definition dekhte hai. “Constants is a value that cannot be changed during execution of the program. For example 12, 15, 40, 4.5, ‘A’ etc.”.

Yani ki constants eak aisa maan (value)hai jise program execution ke time par change nahi kiya ja sakta. Jaise 12, 15, 40, 4.5, ‘A’. Kisi bhi program main constants hum khud he define karte hai.

Constants variable ke use karne ka yah fayda hota hai. Ki yadi aapko bad main constants ko change karna padeto ise aapko program main kai jagah change karne ke jaroorat nahi padti hai. aap sirf constatns variable ki value he change karte hai or vah program main har jagah apne aap change ho jati hai.

Types Of Constants In C++ In Hindi

yadi sahi mayne se dekha jaye to constants sirf two types ke hote hai.

  • First Way Constants variables
  • Second Way Constants Literals

Constants Literals

Wo values jinhe hum program main directly use karte hai. Constants literals kahlati hai. Example ke liye aap neeche likhe gaye sare examples ko dekh lejiyega.

  • Y= s+5;
  • X=s+8;
  • Char=’aman’;

Upar likhe gaye statements 5, 8, ‘aman’ ye sabhi constants literals hai. Inhe program main directly use kiya gya hai. Program execution ke time par inke value change nahi hogi. Agar aap eak bade project par work kar rahe ho to aapko Constants literals ko use karne ke advice nahi di jati hai.

Chalo hum maan lete hai ki koi eak bada program hai. Jisme eak constants literals ka use kai jagah par kiya gya hai. Ab yadi hume constant ko change karne ki requirement hoti hai. To hume har jagah khud find karke constant ko change karna padega.

Note:- “Hume Constant literals ka use kam se kam karna chahiye”.

Constants Variables In C++ In Hindi

Constants variables ko hum khud hi eak variable ki tarah declare karte hai. Inko use karne ka advantage yah hai ki yadi hume constants ke value ko change karna pade to program mian har jagah change karne ki jaroorat nahi hoti hai.

Hum sirf constant variable ki value change karte hai. Or program main har jagah apne aap change ho jati hai. Aap constants variables ke neeche likhe kuch example dekh sakte ho.

Upar likhe gaye example me member, number, array, hmt ye sabhi constants variables hai. jinki value pahle se he define kar di gayi hai.

List Of Constants In C++ In Hindi

Mene aap logo ke liye eak table banayi hai. Jisme mene sabi sabhi tarah ke constants example ke sath likhe hai. To aap inhe bhi pad leejiye.

List Of Constants In Cpp

SNo. Constant Example
1) Decimal Constant 30, 20, 450, 600 etc.
2) Real or Floating-point Constant 15.3, 26.2, 40.6 etc.
3) Octal Constant 021, 033, 046, 076 etc.
4) Hexadecimal Constant 0x2a, 0x7b, 0xaa etc.
5) String Constant “hmt”, “c program”, “hindimetutorial.com” etc.
6) Character Constant ‘x’, ‘y’, ‘z’ etc.

How To Define Constants In C++ In Hindi

We have 2 ways to define constants in c. Yani ke hamare pass c++ language main constants define karne ke liye 2 tareeke hai. To chaliye seekhte hai how to define constants In c.

  1. #define preprocessor
  2. const keyword

C++ #define preprocessor

#define eak preprocessor directive hai. Iska use karke hum constants variable define karte hai. Is directive se Constants variables ko program ki starting me main( ) function se pahle define karte hai. #define preprocessor ke help se define kiye gaye variables ko aap program main kahi bhi use kar sakte hai.

Constants variable ke examples aap neeche dekh sakte hai.

Example 1

Example 2

C++ const keyword

C++ language main hum const keyword ke help se bhi constantans variable declare kar sakte hai. Agar hame kisi function main constant ko use karna hai to const keyword ke sath variable ko define kar sakte hai. const keyword C++ language main kaise define karte hai iska example aap neeche dekh sakte hai.

Example 1

Example 2

Related Lecture

Dear Students, main aasha karta hun ki aapko Constants In C++ Ka Lecture padh kar samjh me aa gaya hoga. Ki constant kya hote hai. Yadi aapako (constants In C++) ke Lecture se related koi bhi problem hai to aap hume comment karke puch skte hai.

Share This Post On

About Author

Thakur Aman Singh

Hey, I am Aman Singh Tomar from Taj City Agra. Through This Blog I want to share my Knowledge with all of you. Read More >>

Leave a Reply

Your email address will not be published. Required fields are marked *