Constants in C

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

Constants ka matlab hota hai jo kabhi change na ho, like 1, 2, 3, 4 and so on. Ye sab maths ke constants hote hai kioki inki values kabhi bhi change nhi ho sakti ye ek universal truth hota hai. Isi tarah se C language mein bhi constants hote hai jinki value ek baar assign karne ke baad change nhi ho sakti.

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;
}
About the Author

Hey, what’s up? I am Shakib Ansari, founder of Beyond Man. I love to help others understand what I have in terms of knowledge...

Comments (0)

No comments yet. Be the first to comment!