Declaration Statement Syntax and Rules in Hindi
/ BCA / Programming with C and CPP
Declaration Statement Syntax and Rules in Hindi
Declaration Statement Syntax and Rules in Hindi
C language में कोई भी variable या constant को use करने से पहले हमें उसे declare करना आवश्यक होता है। Declaration statement के माध्यम से हम compiler को बताते हैं कि कोई variable या constant किस type का data रखेगा और उसका नाम क्या होगा। इस प्रक्रिया को ही declaration कहते हैं।
What is Declaration Statement?
Declaration statement वह statement होता है जिसमें हम variable का नाम और उसका data type define करते हैं। यह एक संकेत देता है कि memory में किस प्रकार का data store किया जाएगा और कितना space allocate किया जाएगा।
Syntax of Declaration Statement
data_type variable_name;
उदाहरण के लिए:
int a;
float salary;
char grade;
- data_type – यह बताता है कि variable किस प्रकार का data store करेगा जैसे int, float, char आदि।
- variable_name – यह उस variable का नाम होता है जिसे हम declare कर रहे हैं।
Rules for Declaration Statement
- Variable को declare करने से पहले उसके नाम में कोई space, special symbol नहीं होना चाहिए (सिर्फ underscore की अनुमति होती है)।
- Variable का नाम alphabet या underscore से शुरू होना चाहिए।
- एक ही variable को दो बार उसी block में declare नहीं किया जा सकता।
- हर declaration के अंत में semi-colon (;) लगाना जरूरी होता है।
- Variable का नाम meaningful और छोटा रखना चाहिए।
Variable Declaration Statement in C Language in Hindi
C language में variable को declare करने के लिए हमें उसका data type और नाम लिखना होता है। जब हम variable declare करते हैं, तब compiler memory में उस variable के लिए जगह reserve करता है। Variable एक ऐसा स्थान होता है जहां हम temporary data को store कर सकते हैं और उसे program में आगे use कर सकते हैं।
Basic Syntax
data_type variable_name;
उदाहरण:
int age;
float percentage;
char gender;
Types of Variables
- Local Variable: जो function के अंदर declare होते हैं और उसी function तक limited रहते हैं।
- Global Variable: जो function के बाहर declare होते हैं और पूरे program में accessible होते हैं।
- Static Variable: जिनका value function call के बाद भी retain रहता है।
- Register Variable: जो CPU register में store किए जाते हैं fast access के लिए।
Example:
#include <stdio.h>
int main() {
int marks;
marks = 85;
printf("Marks = %d", marks);
return 0;
}
Multiple Variable Declaration Statement in Hindi
C language हमें एक ही line में एक से अधिक variables को declare करने की सुविधा देता है, बशर्ते कि सभी variables का data type एक जैसा हो। इससे code ज्यादा readable और compact बनता है।
Syntax
data_type variable1, variable2, variable3;
उदाहरण:
int x, y, z;
float length, width, height;
char a, b, c;
Initialization with Declaration
int a = 5, b = 10, c = 15;
Benefits:
- Code छोटा और साफ-सुथरा रहता है।
- Readability बढ़ती है।
- एक ही data type के कई variables को एक साथ manage करना आसान होता है।
Constant Declaration Statement in Hindi
Constant वो value होती है जिसे program में बाद में बदला नहीं जा सकता। अगर किसी value को पूरे program में fix रखना है तो उसे constant declare किया जाता है। Constant memory में fixed value store करता है जिसे modify नहीं किया जा सकता।
Types of Constant Declaration
1. Using #define
यह एक preprocessor directive होता है जिसे compile होने से पहले ही replace कर दिया जाता है।
#define PI 3.14
#define MAX 100
2. Using const Keyword
const keyword का उपयोग करके भी constant declare किया जा सकता है।
const int a = 10;
const float pi = 3.14;
Difference between #define and const
| Aspect | #define | const |
|---|---|---|
| Scope | Global | Block-specific |
| Data Type | नहीं होता | जरूरी होता है |
| Memory | नहीं लेता | Memory allocate करता है |
Importance of Constants
- Code readable और maintainable बनता है।
- Fixed values को बार-बार use करने में आसानी होती है।
- Error की संभावना कम होती है।
- Program ज्यादा reliable बनता है।
Example Using const:
#include <stdio.h>
int main() {
const int max = 100;
printf("Max value is %d", max);
return 0;
}
Example Using #define:
#include <stdio.h>
#define RATE 50
int main() {
int amount = 10 * RATE;
printf("Total amount = %d", amount);
return 0;
}
ऊपर दिए गए सभी declaration statements C language के foundation concepts में आते हैं। इन्हें सही तरीके से समझना और use करना किसी भी student के लिए जरूरी होता है ताकि वे memory allocation, value storage और syntax-related errors से बच सकें।