Discover how your code can tell you exactly where and when it runs without you lifting a finger!
Why Predefined macros? - Purpose & Use Cases
Imagine writing a C program where you need to include the current date, time, or file name manually every time you compile or debug. You have to type these details yourself or update them each time you change the code.
This manual method is slow and error-prone. You might forget to update the date or file name, leading to confusion during debugging. It also wastes time and makes your code less reliable.
Predefined macros automatically provide useful information like the current file name, line number, compilation date, and time. This saves you from typing or updating these details manually, making your code smarter and easier to maintain.
#include <stdio.h> int main() { printf("File: myfile.c\n"); printf("Line: 10\n"); return 0; }
#include <stdio.h> int main() { printf("File: %s\n", __FILE__); printf("Line: %d\n", __LINE__); return 0; }
It enables your program to automatically know and display important information about itself without extra effort.
When debugging a program, predefined macros like __FILE__ and __LINE__ help you quickly find where an error happened without manually adding that info.
Predefined macros save time by automating code information.
They reduce errors caused by manual updates.
They make debugging and logging easier and more reliable.