Constants and Variables in C language

Constants and Variables

Introduction

Programming में data को store करना बहुत जरूरी होता है। जब हम program बनाते हैं, तो हमें कुछ values को store करना और कभी-कभी उन्हें change करना पड़ता है।

इसी purpose के लिए C language में दो महत्वपूर्ण concept होते हैं:

  • Variables (जिनकी value बदल सकती है)
  • Constants (जिनकी value fix रहती है)

ये दोनों programming की basic building blocks हैं।

Variables

Definition

Variable एक memory location होता है जिसका नाम दिया जाता है और जिसमें value store की जाती है, तथा program के दौरान उसकी value बदली जा सकती है।

Example

int a = 10;
a = 20;

यहाँ:

  • a → variable है
  • पहले value 10 थी, बाद में 20 हो गई

Real World Example

मान लो एक पानी की बोतल है जिसे आप बार-बार भर सकते हैं।

  • कभी 1 लीटर
  • कभी 2 लीटर

इसी तरह variable की value बदल सकती है।

Constants

Definition

Constant वह value होती है जिसे program के दौरान बदला नहीं जा सकता।

Example

const int a = 100;

यहाँ:

  • a की value हमेशा 100 रहेगी
  • इसे change नहीं कर सकते

Real World Example

मान लो आपकी जन्म तिथि (Date of Birth) है।

  • यह एक बार तय हो जाती है
  • इसे बदला नहीं जा सकता

इसी तरह constant की value fix होती है।

Difference Between Variable and Constant

VariableConstant
Value बदल सकती हैValue fix रहती है
Program के दौरान update होती हैChange नहीं होती
Memory में normal storageFixed value storage
Example: int x = 10Example: const int x = 10

Exam Points

  • Variable की value change हो सकती है
  • Constant की value change नहीं होती
  • const keyword constant बनाने के लिए use होता है
  • Variable memory location को represent करता है

Leave a Comment

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

Scroll to Top