Advertisement
Beginner C++, Preprocessor & Macros

What are predefined macros like __LINE__ and __FILE__?

Short answer

The preprocessor provides built-in macros: __LINE__ (current line number), __FILE__ (source file name), __DATE__/__TIME__ (build date/time), __func__ (function name), and __cplusplus (the C++ standard version).

Save C++ mock interview
Advertisement
AModel answer
The preprocessor provides built-in macros: __LINE__ (current line number), __FILE__ (source file name), __DATE__/__TIME__ (build date/time), __func__ (function name), and __cplusplus (the C++ standard version). They're commonly used in logging, assertions, and diagnostics to report where events occurred.
std::cout << __FILE__ << ":" << __LINE__ << "\n";
Real-world example
A logging macro embeds __FILE__ and __LINE__ so each message shows where it was emitted.
Likely follow-ups
  • What does __cplusplus indicate? | Where are these used?
Related topics