0
0
Cprogramming~10 mins

Predefined macros - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the current line number using a predefined macro.

C
#include <stdio.h>

int main() {
    printf("Line number: %d\n", [1]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A__DATE__
B__FILE__
C__TIME__
D__LINE__
Attempts:
3 left
💡 Hint
Common Mistakes
Using __FILE__ instead of __LINE__ which prints the file name.
Using __DATE__ or __TIME__ which print date or time, not line number.
2fill in blank
medium

Complete the code to print the current file name using a predefined macro.

C
#include <stdio.h>

int main() {
    printf("File name: %s\n", [1]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A__FILE__
B__LINE__
C__DATE__
D__TIME__
Attempts:
3 left
💡 Hint
Common Mistakes
Using __LINE__ which gives a number, not a string.
Using __DATE__ or __TIME__ which give date or time, not file name.
3fill in blank
hard

Fix the error in the code to print the compilation date using a predefined macro.

C
#include <stdio.h>

int main() {
    printf("Compiled on: %s\n", [1]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A__DATE__
B__LINE__
C__FILE__
D__TIME__
Attempts:
3 left
💡 Hint
Common Mistakes
Using __TIME__ which gives time, not date.
Using __FILE__ or __LINE__ which give file name or line number.
4fill in blank
hard

Fill both blanks to print the compilation date and time using predefined macros.

C
#include <stdio.h>

int main() {
    printf("Compiled on: %s at %s\n", [1], [2]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A__DATE__
B__TIME__
C__FILE__
D__LINE__
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of date and time macros.
Using __FILE__ or __LINE__ instead of date/time macros.
5fill in blank
hard

Fill all three blanks to print the file name, line number, and compilation time using predefined macros.

C
#include <stdio.h>

int main() {
    printf("File: %s, Line: %d, Time: %s\n", [1], [2], [3]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A__FILE__
B__LINE__
C__TIME__
D__DATE__
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of macros.
Using __DATE__ instead of __TIME__ for the time.