ASK A QUESTION

    Constants in Hindi

in Hindi - Constants



Constants

  • Constant की value fixed होती है |
  • Constant किसी भी data type का हो सकता है |
  • Constant को Literals भी कहते है |
  • Constant Pointer भी होता है |

Syntax :
const data_type variable_name = value (optional) ;

Constant के प्रकार :

  • Integer Constant
  • Decimal Constant
  • Octal Constant
  • Hexadecimal Constant
  • Floating-point / Real Constant
  • Character Constant
  • String Constant
  • Preprocessor


With Examples

Constant Typeswith Examples
Integereg. 2, 10, -2
Decimal (Integer) eg. 2, 10, -2
Octal (Integer)eg. 02, 010
Hexadecimal (Integer)eg. 0x12, 0x1f
Floating-point/Realeg. -2.4, 4.8
Charactereg. 'i', 'j'
Stringeg. "Hello", "Hi"
Preprocessoreg. #define a 5

 

Integer Constant Types:

  1. Decimal Integer Constant
  2. Octal Integer Constant
  3. Hexadecimal Integer Constant
Integer Constants
  • Integer Constant normal Variable की तरह काम करता है |
  • Integer Constant positive (+) या negative (-) हो सकता है |
  • Integer Constant की Range -32768 से 32767 तक होती है |

for eg.
Source Code :
#include <iostream.h>
using namespace std;

int main(){

const int num = 5; // integer Constant

    cout<<"integer constant value : "<<num;

return 0;
}
Output
integer constant value : 5

Character Constants
  • Character Constant normal Variable की तरह काम करता है |
  • Character Constant सिर्फ single character लेता है | |
  • Escape Sequences के साथ भी character constant इस्तेमाल किया जाता है |

Escape SequencesExplaination
\'Single Quotation Mark
\"Double Quotation Mark
\\Backslash
\?Question Mark
\aAudible Bell
\bBackspace
\fForm Feed
\nNew line
\rCarriage Return
\hHorizontal Tab
\vVertical Tab

 

for eg.
Source Code :
#include <iostream.h>
using namespace std;

int main(){

const char ch = 'H'; // character constant
const char escape[]= "Hello\tWorld"; // Escape sequence - Horizontal Tab and string constant

    cout<<"Character constant : "<<ch<<endl;
    cout<<"String constant : "<<escape<<endl;

return 0;
}

Output
Character constant : H
String constant : Hello      World

Floating-point Constant
  • Floating-point Constant normal float variable की तरह ही काम करता है |
  • Floating-point Constant में Decimal point (.) होता है |
  • अगर Floatint-point Constant की value integer type की हो तो वो Decimal point (.) लेता है |

for eg.
Source Code :
#include <iostream.h>
using namespace std;

int main(){

const float num1 = 5; 
const float num2 = 3.525984; // Floating-point constant

    cout<<"Floating-point constant : "<<num1<<endl;
    cout<<"Floating-point constant : "<<num2;

return 0;
}
Output
Floating-point constant : 5
Floating-point constant : 3.525984

String Constant
  • String Constant की value Double Quotation Mark (" ") के अंदर लिखी जाती है |
  • String Constant Single और Multiple characters लेता है |
  • String Constant Escape Sequences के साथ भी इस्तेमाल करते है |

for eg.
Source Code :
#include <iostream.h>
using namespace std;

int main(){

const char str1 []= "H"; // String Constant with single character
const char str2 []= "Hello World"; // Normal String constant
const char str3 [] = "Hello\nWorld"; // String Constant with Escape Sequence

    cout<<"String Constant with single character : "<<str1<<endl;
    cout<<"Normal String constant : "<<str2<<endl;
    cout<<"String Constant with Escape Sequence : "<<str3<<endl;

return 0;
}

Output
String Constant with single character : H
Normal String constant : Hello World
String Constant with Escape Sequence : Hello
World

Preprocessor Constant
  • Preprocessor के साथ भी Constant value रख सकते है |

for eg.
Source Code :
#include <iostream.h>
#define a 5 // Constant value with preprocessor
#define b 10 // Constant value with preprocessor
using namespace std;


int main(){

    cout<<"Value of a  : "<<a<<endl;
    cout<<"Value of b  : "<<b;

return 0;
}
Output
Value of a  : 5
Value of b  : 10