What is Constant in Hindi - C में Constant क्या है

Constant भी Variable के समान ही Value Store करने वाला Container है लेकिन Variable के विपरीत Constant मे Store Value को Program Execution के दौरान Change या Modify नही किया जा सकता दूसरे शब्दों में कहे तो ये Fixed Value रखते हैं
अतः Constant का Use उस समय
किया जाता है जब हम Fix Value रखना चाहते है जिसे Change न किया जा सके।

जब हम इसके Value को Change करने का प्रयास करते है तब हमे Error आता है। Constant बनाने के लिए const keyword का Use किया जाता है

Example:

const int a = 10;

C मे Constant Define करने का तरीका

C में दो तरीके से Constant Define किए जाते है।
1) const keyword
2) #define Preprocessor का प्रयोग कर

1) const keyword का प्रयोग करके

C मे Constant Define करने के लिए const keyword का प्रयोग निम्न प्रकार से किया जाता है

const float PI = 3.14
ऊपर हम PI की Value को Change नही कर सकते क्योंकि वह एक Constant बन चुका है

Program to define Constant by using const keyword 
#include<stdio.h>
int main()
 {
// Defining constant 
 const float PI = 3.14;
 printf("The value of Pi is: %f", PI);
return 0;
 }
 

Output:
The value of Pi is: 3.14

यदि आप PI कि Value Change करने का प्रयास करेंगे तो आपको Complie Time में Error आयेगा

2) #define Preprocessor का प्रयोग कर

आप #define Preprocessor का प्रयोग करके भी निम्न प्रकार से Constant Define कर सकते है


Program to define constant by using #define Preprocessor 
#include<stdio.h>
#define PI 3.14
int main()
 {
 printf("The value of Pi is: %f", PI);
return 0;
 }
 

Output:
The value of Pi is: 3.14

C Language मे Constant के प्रकार

Constant कई प्रकार के होते है जो निम्न है।
1) Numeric Constant
2) Character Constant
3) String Constant
4)Backslash Character Constant

1) Numeric Constant

Numeric Constant में Numbers शामिल होते है
इसे आगे निम्न भागों में बांटा गया है
a) Integer Constant
b) Floating Point Constant

a) Integer Constant

Integer Constant में बिना Decimal Point या Fractions के Whole Number होते है
इसमे Positive और Negative Numbers शामिल है

Example:

const int x = 24;
const int y = -45;
const int z = 849;

Integer Constant के प्रकार

Integer Constant के निम्न प्रकार होते है
I) Decimal Integer Constant
II) Octal Integer Constant
III) Hexadecimal Constant

Decimal Integer Constant(Base 10)

एक Decimal Integer Constant का निर्माण (0 से 9) Digits के Combination का Use करके बनाते है

Examples:

const decNum x = 4567;
const int y = 123;

Octal Integer Constant(Base 8)
एक Octal Integer Constant का निर्माण (0 से 7) तक Digits के Combination का Use करके बनाते है लेकिन इसका पहला शुरुवाती Digit , '0' होना चाहिए ताकि उसे Octal Integer Constant के रूप मे पहचाना जा सके।

Example:

int octalNum = 052; 
int a = 047"

Hexadecimal Integer Constant
एक Hexadecimal Integer Constant का निर्माण (0 से 9) तथा (A से F या a से f) तक के Letters(Uppercase या Lowercase) के Combination का Use करके बनाते है इसकी शुरुवात हमेशा 0x या 0X से होनी चाहिए

Example:

int hexNum = 0x2A;
const int a = 0x2A6;

Program for all types of Integer(Decimal, Octal, Hexadecimal) Constant
#include<stdio.h>
int main() 
{
 //Decimal constant defined
const int decimal_constant = 62;

//Octal constant defined
const int octal_constant = 072; 

//Hexadecimal constant defined
const int hexa_constant = 0x64B; 

printf("Value of decimal constant is : %d\n", decimal_constant);

printf("Value of octal constant is : %d\n", octal_constant);

printf("Value of hexadecimal constant is : %d\n", hexa_constant);
    return 0;
} 
 

Output:
Value of decimal constant is : 62
Value of octal constant is : 58
Value of hexadecimal constant is : 1611

b) Floating Point Constant

इसमे Real Numbers को Store किया जाता है जिसमें Decimal Point या Fractions शामिल होते हैं साथ ही इसमें Positive और Negative Value होते है

Example:

float a = 27.55;
float pi = 3.14;        



Program for Floating Point Constant 
#include<stdio.h> 
int main() 
{ 
//Defining Floating Point Constant
const float PI = 3.14;
const float x = 5.6;

printf("The value of PI is:%f\n", PI);
printf("The value of x is:%f", x);
return 0;
 }
 
Output:
The value of PI is:3.140000
The value of x is:5.600000

2) 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 = '#';


Program for Character Constant
#include<studio.h> 
int main() 
{ 
//Defining Character constant
const char my_letter = 'A';
const char show_letter = 'd';
const char digit_char = '9';

printf("Value of my-letter
is:%c\n", my_letter);
printf("Value of show-letter is:%c\n", show_letter);
printf("Value of digit-letter is:%c\n", digit_char);
return 0;
 }
 

Output:
Value of my-letter is: A
Value of show-letter is: d
Value of digit-letter is : 9

3) String Constant

एक String Constant , Characters का एक Sequence होता है जिसे Double quotation mark के अंदर लिखा जाता है।

Example:

const my_string = "abcde";
const my_num = "4567";
const my_symbol = "@@@@";


Program for String Constant
#include<stdio.h> 
int main() 
{ 
//Defining string constant
char my_string1[ ] ="I'm using string constant";
char my_string2[ ] ="Hey, I'm learning c";

printf("%s\n",my_string1);
printf("%s\n",my_string2);
return 0;
 }
 

Output:
I'm using string constant
Hey, I'm learning c


4) Backslash Character Constant

C Language में कुछ Character को '\' Backslash कर साथ प्रयोग करने की अनुमति होती है, जिसका प्रयोग हम Program के Instruction लिखने के समय करते है.

Backslash के साथ English के Lower Case Letters (a to z) का Use किया जाता है
 
Backslash Meaning 

 '\n' Newline
'\t' Horizontal Tab
'\r' Carriage return
'\b' Backspace
'\a' Audible Alert (bell)
'\f' Form feed
'\\' Backslash 
 '\' Single quote
 '\" ' Double quote
'\v' Vertical Tab
'\?' Question Mark

उपरोक्त Constants के अतिरिक्त कुछ अन्य Constants निम्न है

1) Array Constant

Array एक ही प्रकार के Data Types वाले Elements का संकलन है
वास्तव में Array स्वयं एक Constant नही है लेकिन हम Arrays में const Keyword का Use करके Array के लिए constant Pointer का निर्माण कर सकते हैं ।

Example:

const int marks[5] = {56, 98, 67, 40, 66};
     

2) Pointer Constant

C में Pointers Variables होते है जो memory addresses को Store करते है हम const keyword का Use करके निम्न प्रकार से constant pointers का निर्माण कर सकते है

 Example:
   
     int a = 64;
  const int *ptr = &a;
  
     int b = 87;
     int *const ptr = &b;


3) Enum

C language में एक enumeration (enum) एक User-defined data type है जो Integer Value के एक Set को Represent करते है इसे बनाने के लिए enum keyword का प्रयोग किया जाता है

Example:

enum Fruits{Apple, Grapes, Pear, Banana, Orange};
 
ऊपर Example मे Fruits एक enum प्रकार है तथा Apple, Grapes, Pear, Banana, Orange enum constants है जिसके लिए

Default Integer Value जो 0 से शुरू होती है Assign किया जाता है 
जैसे Apple के लिए Assigned Value 0 है, Grapes के लिए 1, Pear के लिए 2 , Banana के लिए 3 और Orange के लिए 4 है
हम enum Constant के लिए आवश्यकतानुसार कोई अन्य विशेष Value Assign कर सकते है 

Difference between Variable and Constant in Hindi in C Language

1) 
Variable Computer के  Storage Location को प्रदर्शित करता है जिसके Value को Program execution के दौरान बदला जा सकता है

Constant एक Value को प्रदर्शित करता है जो fixed रहता है जिसे Change नही किया जा सकता

2)
Variable को Declare करने के लिए Data Type का Use करते है

Constant को Declare करने के लिए const या #define  keyword का Use करते है

3)
Variable को Declare करते समय या बाद मे Value Assign कर Initialize किया जाता है

Constant को Declare करते समय ही Value Assign कर Initialize करना होता है

4)
Variable को बनाने के लिए Letters या Symbol Use किया जाता है

Constant को बनाने के लिए Numbers का Use किया जाता है
5)
Variable के Example
int a = 19;
float marks = 67.45;

Constant के Example
#define PI 3.14;
const float PI =3.14;

 Related Post