0
0
Cprogramming~15 mins

Predefined macros - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Predefined Macros in C
📖 Scenario: You are writing a simple C program that needs to display information about when and where it was compiled. This is useful for debugging and tracking versions.
🎯 Goal: Build a C program that uses predefined macros to show the current date, time, and file name of the source code.
📋 What You'll Learn
Use the predefined macro __DATE__ to get the compilation date
Use the predefined macro __TIME__ to get the compilation time
Use the predefined macro __FILE__ to get the source file name
Print these values clearly labeled
💡 Why This Matters
🌍 Real World
Developers often use predefined macros to embed build information in programs for debugging and version tracking.
💼 Career
Knowing how to use predefined macros is useful for software developers working on C projects, especially in embedded systems and system programming.
Progress0 / 4 steps
1
Create a C program skeleton
Write the initial C program with #include <stdio.h> and an empty main function that returns 0.
C
Need a hint?
Start by including the standard input-output header and create the main function.
2
Add variables for predefined macros
Inside main, create three const char* variables named compile_date, compile_time, and source_file. Assign them the values __DATE__, __TIME__, and __FILE__ respectively.
C
Need a hint?
Use the predefined macros exactly as shown to assign the variables.
3
Print the predefined macro values
Use printf to display the labels and values of compile_date, compile_time, and source_file on separate lines.
C
Need a hint?
Use printf with %s to print each string variable with a label.
4
Run and display the output
Run the program and print the output showing the compilation date, time, and source file name.
C
Need a hint?
Run the program to see the compilation details printed.