predefined macros in C

Introduction

C language में कुछ ऐसे macros पहले से defined होते हैं, जिन्हें predefined names (predefined macros) कहा जाता है।

ये macros automatically compiler द्वारा define किए जाते हैं और program को current information (date, time, file, line number आदि) प्रदान करते हैं।

Important बात:

  • इन्हें हमें define करने की जरूरत नहीं होती
  • ये preprocessor के द्वारा handle किए जाते हैं
  • debugging और information display में बहुत useful होते हैं

Common Predefined Macros

MacroMeaning
__DATE__Current date
__TIME__Current time
__FILE__Current file name
__LINE__Current line number
__STDC__Compiler ANSI standard follow करता है या नहीं

1. __DATE__ Macro

यह program compile होने की current date को return करता है।

Example Program:

#include <stdio.h>

int main() {
printf("Current Date: %s\n", __DATE__);
return 0;
}

Explanation

  • __DATE__ compile time की date देता है
  • यह string format में होता है (जैसे: Apr 05 2026)

Output Example:

Current Date: Apr 05 2026

2. __TIME__ Macro

यह program compile होने का current time return करता है।

Example Program:

#include <stdio.h>

int main() {
printf("Current Time: %s\n", __TIME__);
return 0;
}

Explanation

  • __TIME__ compile time का time देता है
  • format होता है: HH:MM:SS

Output Example:

Current Time: 10:30:45

3. __FILE__ Macro

यह current file का नाम return करता है।

Example Program:

#include <stdio.h>

int main() {
printf("File Name: %s\n", __FILE__);
return 0;
}

Explanation

  • यह उस file का नाम दिखाता है जिसमें program लिखा है
  • debugging में useful होता है

Output Example:

File Name: main.c

4. __LINE__ Macro

यह current line number return करता है।

Example Program:

#include <stdio.h>

int main() {
printf("Line Number: %d\n", __LINE__);
return 0;
}

Explanation

  • यह उस line का number देता है जहाँ macro लिखा गया है
  • debugging और error tracking में helpful है

Output Example:

Line Number: 5

5. Combined Example (All Macros Together)

#include <stdio.h>int main() {    printf("Date: %s\n", __DATE__);
printf("Time: %s\n", __TIME__);
printf("File: %s\n", __FILE__);
printf("Line: %d\n", __LINE__); return 0;
}

Explanation

इस program में सभी predefined macros को एक साथ use किया गया है:

  • Date → compile time की date
  • Time → compile time का time
  • File → current file name
  • Line → current line number

Output Example:

Date: Apr 05 2026
Time: 10:35:20
File: main.c
Line: 8

Predefined Macros ka Use

1. Debugging

Error कहाँ आया है यह पता लगाने में मदद करता है

2. Logging

Program execution की information store करने में

3. Information Display

Program के बारे में details दिखाने में

Important Points

  • ये macros predefined होते हैं (already defined)
  • इन्हें redefine नहीं करना चाहिए
  • ये compile time information देते हैं
  • debugging में बहुत important होते हैं

Conclusion

Predefined names (macros) C language का एक powerful feature हैं, जो program को runtime से पहले important information provide करते हैं।

इनका use debugging, logging और program tracking में बहुत ज्यादा किया जाता है।
__DATE__, __TIME__, __FILE__, और __LINE__ सबसे commonly used predefined macros हैं।

Leave a Comment

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

Scroll to Top