Constants, Variables, and Data Types in C.

By Shakib Ansari | Date: Sun, Mar 30, 2025

C Language me ek program ko efficient tareeke se likhne ke liye hame Constants, Variables, and Data Types ki understanding hona bahut hi zaruri hai. Ye sab C Language ke basic fundamentals hote hai jo ki ek good programmer ko learn karne chahiye.

1. Constants

Constants fixed values hoti hai jo ki kabhi change nhi hoti during the execution of progam.

Constants alag-alag types ke hote hai:

Types of Constants:

  1. Integer Constants - Integer Constants mein whole numbers hote hai without fractional part(e.g., 10, -20, 100)
  2. Floating Point Constants - Aise numbers jisme Decimal Values bhi include hoti hai(e.g., 3.14, -0.987)
  3. Character Constants - Ek single character jo ki single quotes mein enclosed hota hai(e.g., 'A', '5')
  4. String Constants - Characters ke sequence jo ki double quotes mein enclosed hota hai(e.g., "Hello World")
  5. Symbolic Constants - Aise constants jo symbol use karte hai(eg. #define or const keyword)

Example of Constants in C:

#include <stdio.h>
#define PI 3.14159 // Symbolic constant

int main() {
    const int AGE = 25; // Constant using 'const' keyword
    printf("Value of PI: %f", PI);
    printf("Age: %d", AGE);
    return 0;
}

2. Variables

Variable ek storage location hoti memory mein jo ki kisi value ko hold karta hai. Ye value change ho sakti hai during the execution of progam.

Rules for Naming Variable

  1. Variable name ke start mein (A-Z or a-z) or ek underscore _
  2. Variable name mein letters, digit(0-9), aur underscore _
  3. Variable name koi keyword nhi ho sakta (e.g., int, return)
  4. Variable name case-sensitive hote hai (e.g., age aur Age alag hai)

Example of Variables in C:

#include <stdio.h>

int main() {
    int age = 20; // Integer variable
    float price = 99.99; // Floating point variable
    char grade = 'A'; // Character variable
    
    printf("Age: %d", age);
    printf("Price: %.2f", price);
    printf("Grade: %c", grade);
    return 0;
}

3. Data Types

Data Types ye specify karte hai ki variable kis type ki value ko hold kar sakta hai. In C, data types ko ham categorized is tarah se kar sakte hai:

3.1 Basic Data Types

  1. int (size: 4 bytes, eg. 10, -20, 100)
  2. float (size: 4 bytes, eg. 3.14, -0.99)
  3. double(size: 8 bytes, eg. 3.1415926535)
  4. char(size: 1 bytes, eg. 'A', 'b', '5')

3.2 Derived Data Types

  • Array (e.g., int arr[5];)
  • Pointer (e.g., int *ptr;)
  • Structure (e.g., struct student {int id; char name[20];};)
  • Union (e.g., union data {int id; float price;};)

Note: Derived Data Types ko Detail Mein Samajhne Ke Liye derived_data_type_blog_link

Example of Data Types in C:

#include <stdio.h>


int main() {
    int number = 100;
    float pi = 3.14;
    char letter = 'C';
    double largeDecimal = 12345.6789;
    
    printf("Integer: %d", number);
    printf("Float: %.2f", pi);
    printf("Character: %c", letter);
    printf("Double: %lf", largeDecimal);
    return 0;
}

Conclusion

Constants, Variables, Data Types ki understanding bahut hi zaruri hoti hai kisi C Program ko efficient tareeke se samjhne ke liye. Constants fixed values hoti hai, Variable aisa data hold karte hai jo ki changeable hota hai, and data types ye define karte hai ki variable kis type ki value ko hold kar sakta hai.


About the Author

Hi, I'm Shakib Ansari, Founder and CEO of BeyondMan. I'm a highly adaptive developer who quickly learns new programming languages and delivers innovative solutions with passion and precision.

Shakib Ansari
Programming

Comments


    User Avatar

    He

    User Avatar

    Helloc

    User Avatar

    Very Good

    User Avatar

    he

    User Avatar

    Listen