Predefined Macros in C with Examples Last Updated : 21 Dec, 2021 Comments Improve Suggest changes Like Article Like Report According to C89 Standard, C programming language has following predefined macros: __LINE__ Macro: __LINE__ macro contains the current line number of the program in the compilation. It gives the line number where it is called. It is used in generating log statements, error messages, throwing exceptions and debugging codes. Whenever the compiler finds an error in compilation it first generates the line number at which error occurred using __LINE__ and prints error message along with line number so that user can easily fix that error easily. C #include <stdio.h> int main() { printf("Line number is: %d\n", __LINE__); return 0; } Output: Line number is: 5 __FILE__ Macro: __FILE__ macro holds the file name of the currently executing program in the computer. It is also used in debugging, generating error reports and log messages. C #include <stdio.h> int main() { printf("File name of this" " program is: %s\n", __FILE__); return 0; } Output: File name of this program is: /usr/share/IDE_PROGRAMS/C/other/703ad0b087fbd7d18cde5ea81f148f36/703ad0b087fbd7d18cde5ea81f148f36.c __DATE__ Macro: __DATE__ macro gives the date at which source code of this program is converted into object code. Simply put, it returns the date at which the program was compiled. Date is in the format mmm dd yyyy. mmm is the abbreviated month name. C #include <stdio.h> int main() { printf("Program Compilation Date: %s\n", __DATE__); return 0; } Output: Program Compilation Date: Dec 26 2019 __TIME__ Macro: __DATE__ macro gives the time at which program was compiled. Time is in the format hour:minute:second. C #include <stdio.h> int main() { printf("Time of compilation is: %s\n", __TIME__); return 0; } Output: Time of compilation is: 13:17:20 __STDC__ Macro: __STDC__ Macro is used to confirm the compiler standard. Generally it holds the value 1 which means that the compiler conforms to ISO Standard C. C #include <stdio.h> int main() { printf("Compiler Standard Number: %d\n", __STDC__); return 0; } Output: Compiler Standard Number: 1 __STDC__HOSTED Macro: This macro holds the value 1 if the compiler’s target is a hosted environment. A hosted environment is a facility in which a third-party holds the compilation data and runs the programs on its own computers. Generally, the value is set to 1. C #include <stdio.h> int main() { printf("STDC_HOSTDED Number: %d\n", __STDC_HOSTED__); return 0; } Output: STDC_HOSTDED Number: 1 __STDC_VERSION__: This macro holds the C Standard’s version number in the form yyyymmL where yyyy and mm are the year and month of the Standard version. This signifies which version of the C Standard the compiler conforms to. Values hold by __STDC_VERSION__ The value 199409L signifies the C89 standard amended in 1994. This is the current default standard. The value 199901L signifies the C99 standard The value 201112L signifies the 2011 revision of the C standard These standard values are changed when the user is required to use the function or header file in C89 standard which is removed in C99 standard. The compiler changes its standard of execution and runs the output. Check out this article which changes the standard to run asctime_s() function declared in the C89 standard. C #include <stdio.h> int main() { printf("Compiler Standard " "VERSION Number: %ld\n", __STDC_VERSION__); return 0; } Output: Compiler Standard VERSION Number: 201112 Predefined Macros in C99 standard: __cplusplus: __cplusplus Macro is defined when the C++ compiler is used. It is used to test whether a header is compiled by a C compiler or a C++ compiler. This macro gives value similar to __STDC_VERSION__, in that it expands to a version number. Values hold by __cplusplus 199711L for the 1998 C++ standard 201103L for the 2011 C++ standard 201402L for the 2014 C++ standard 201703L for the 2017 C++ standard __OBJC__ Macro:: __OBJC__ Macro has value 1 if the Objective-C compiler is in use. __OBJC__ is used to test whether a header is compiled by a C compiler or an Objective-C compiler. References: https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html Comment More infoAdvertise with us Next Article Predefined Macros in C with Examples A avsadityavardhan Follow Improve Article Tags : Programming Language C Language C Macro Similar Reads Multiline macros in C In this article, we will discuss how to write a multi-line macro. We can write multi-line macro same like function, but each statement ends with "\". Let us see with example. Below is simple macro, which accepts input number from user, and prints whether entered number is even or odd. C #include 3 min read Formatted and Unformatted Input/Output functions in C with Examples In C language, the Input/Output (I/O) functions are part of the standard library, and these functions are used for interacting with the user or other systems, to perform operations such as reading input and printing output. These functions provide ways to read data from files and other input devices 7 min read Write a C program that won't compile in C++ Although C++ is designed to have backward compatibility with C, there can be many C programs that would produce compiler errors when compiled with a C++ compiler. Following is the list of the C programs that wonât compile in C++: Calling a function before the declarationUsing normal pointer with con 4 min read Write a C macro PRINT(x) which prints x At the first look, it seems that writing a C macro which prints its argument is child's play.  Following program should work i.e. it should print x c #define PRINT(x) (x) int main() { printf("%s", PRINT(x)); return 0; } But it would issue compile error because the data type of x, which is taken as 1 min read How to Change the Output of printf() in main() in C? To change the output of printf() in main(), we can use Macro Arguments. #define macro can be used for this task. This macro is defined inside the function. Although, #define can be used without declaring it in the function, in that case always the printf() will be changed. The function needs to be c 2 min read Like