Define Constants in C++ in Hindi
2) #define Preprocessor का Use करके
const keyword का प्रयोग करके
C++ मे`const` Keyword का Use करके Constant को Define करने का यह तरीका मुख्य और ज्यादा Use की जाती हैं 'const' keyword का Use constant define करने के लिए निम्न प्रकार से किया जाता है#include<iostream>
using namespace std;
int main()
{
const int myNum = 45;
const float PI = 3.14;
cout << "Value of myNum:"<< myNum<<endl;
cout << "Value of PI is:"<< PI;
return 0;
}
#define Preprocessor का प्रयोग कर
#include<iostream>
using namespace std;
#define myNum 10
#define PI 3.14
int main()
{
cout<<"The value of myNum is:"<<myNum<<endl;
cout<<"The value of PI is:"<<PI<<endl;
return 0;
}
constexpr keyword का Use करके
#include<iostream>
using namespace std;
int main()
{
int constexpr Num = 26;
cout<<"The value of Num is:"<<Num;
return 0;
}
C++ Language में Constant के प्रकार
1) Integer constants
Integer Constant
Integer Constant एक Whole number है अर्थात इसमें Decimal Point नही होतेTypes of Integer Constants
I) Decimal Integer Constant
II) Octal Integer Constant
III) Hexadecimal Constant
Decimal Integer Constant(Base 10)
एक Decimal Integer Constant को '0' से '9' तक कोई भी Digits के Combination से बनाया जाता हैExamples
const deConstant = 4567;
const int x = 674;
Octal Integer Constant(Base 8)
एक Octal Integer Constant का निर्माण (0 से 7) तक Digits के Combination का Use करके बनाते है लेकिन इसका पहला शुरुवाती Digit , '0' होना चाहिए ताकि उसे Octal Integer Constant के रूप मे पहचाना जा सके
int octConstant = 0642;
int x = 047"
Hexadecimal Integer Constant
एक Octal Integer Constant का निर्माण (0 से 9) तथा (A से F या a से f) तक के Letters(Uppercase या Lowercase) के Combination का Use करके बनाते है इसकी शुरुवात हमेशा 0x या 0X से होनी चाहिएExample
int hexNum = 0x2A;
const int a = 0x2A6;
#include<iostream>
using namespace std;
int main()
{
//Decimal constant defined
const int decConstant = 802;
//Octal constant defined
const int octalConstant = 0732;
//Hexadecimal constant defined
const int hexaConstant = 0x72C;
//Printing all the Integer Constants
cout<<"Value of decimal constant is: "<<decConstant<<endl;
cout<<"Value of octal constant is: "<<octalConstant,<<endl;
cout<<"Value of Hexadecimal constant is: "<<hexaConstant;
return 0;
}
Floating Point Constant
इसमे Real Numbers को Store किया जाता है जिसमें Decimal Point या Fractions शामिल होते हैं साथ ही इसमें Positive और Negative Value होते हैExample
float a = 22.45;
float pi = 3.14;
#include<iostream>
using namespace std;
int main()
{
//Defining Floating Point Constant
const float PI = 3.14;
const float x = 4.6;
cout<<"The value of PI is:"<< PI<<endl;
cout<<"The value of x is:"<< x;
return 0;
}
Character Constant
Character Constant को Single Character(letter, digit,symbol) से प्रदर्शित किया जाता हैइसे लिखने के लिए Single Quotation Mark का Use करते है
Example
char my_letter = 'A';
char x = 'C';
char y = '7';
char mySymbol = '#';
#include<iostream>
using namespace std;
int main()
{
//Defining Character constant
const char myLetter = 'D';
const char digitChar = '7';
cout<<"Value of my-letter is:"<<myLetter<<endl;
cout<<"Value of digit-letter is:"<< digitChar;
return 0;
}
Value of myLetter is: D
Value of digitChar is : 9
String Constant
एक String Constant , Characters का एक Sequence होता है जिसे Double quotation mark के अंदर लिखा जाता हैExample
const myStr = "xyz";
const myNum = "1234";
const mySymbol = "$$$$";
#include<iostream>
using namespace std;
int main()
{
/Defining string constant
char myStr1[ ] ="Welcome to Computerehub";
char myStr2[ ] ="Here, we are learning string constant in C++";
cout<<myStr1<<endl;
cout<<myStr2;
return 0;
}
Output:
Difference between Variable and Constant in Hindi in C++ Language
Related Posts
> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान
> Basic structure of C++ Program
> C++ में Tokens क्या है? और उसके प्रकार
> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं
> C++ में Basic Input और Output (cin,cout,cerr) की जानकारी
> Data type in C++ की संपूर्ण जानकारी
> C+ में Operators और उसके प्रकार जानें Practical सहित
> C++ में Conditional और उसके प्रकारों को जानें Practical सहित
> C++ में Looping statements और उसके प्रकार Practical सहित
> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित
> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित
> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित
> C++ में Structure क्या है Practical सहित
> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में
> Oops के फायदे और नुकसान की जानकारी
> C++ में Class और Object की सम्पूर्ण जनकारी
> C++ में Array of Objects क्या है?
> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।
> C++ में Passing objects क्या है
> C++ में Reference और Type Casting की संपूर्ण जानकारी
> C++ में Access specifier की संपूर्ण जानकारी
> C++ में Static Data Members और Member Functions के बारे में Practical सहित
> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित
> Friend Function in C++ in Hindi
> Friend Class in C++ in Hindi Practical सहित
> Inline function in C++ in Hindi
> Function Overloading in C++ in Hindi Practical सहित
> Operator Overloading in C++ in Hindi Practical सहित
> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी
> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी
> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित
> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें
> C++ में Virtual function की संपूर्ण जानकारी
> C++ में File handling की संपूर्ण जानकारी
> C++ में Exception handling की संपूर्ण जानकारी
0 टिप्पणियाँ