0
0
Cprogramming~20 mins

Predefined macros - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Predefined Macros Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of __FILE__ and __LINE__ macros
What is the output of this C program when compiled and run?
C
#include <stdio.h>

int main() {
    printf("File: %s, Line: %d\n", __FILE__, __LINE__);
    return 0;
}
AFile: main.c, Line: 7
BFile: main.c, Line: 6
CFile: main.c, Line: 4
DFile: main.c, Line: 5
Attempts:
2 left
💡 Hint
Remember that __LINE__ expands to the line number where it appears in the source code.
Predict Output
intermediate
2:00remaining
Output of __DATE__ and __TIME__ macros
What will this program print when compiled and run?
C
#include <stdio.h>

int main() {
    printf("Compiled on %s at %s\n", __DATE__, __TIME__);
    return 0;
}
ACompiled on Jun 15 2024 at 10:00:00 (example)
BCompiled on 2024-06-15 at 10:00:00
CCompiled on Jun 15 2024 at 10:00:00
DCompiled on Jun 15 2024 at 10:00:00 (actual compile time)
Attempts:
2 left
💡 Hint
The __DATE__ macro expands to a string literal in the format "Mmm dd yyyy".
Predict Output
advanced
2:00remaining
Output of __STDC__ macro
What is the output of this program if compiled with a standard C compiler?
C
#include <stdio.h>

int main() {
#ifdef __STDC__
    printf("Standard C compiler detected\n");
#else
    printf("Non-standard compiler\n");
#endif
    return 0;
}
AStandard C compiler detected
BNon-standard compiler
CCompilation error due to undefined macro
DNo output
Attempts:
2 left
💡 Hint
The __STDC__ macro is defined by standard C compilers.
Predict Output
advanced
2:00remaining
Output of __func__ macro inside a function
What does this program print when run?
C
#include <stdio.h>

void greet() {
    printf("Function name: %s\n", __func__);
}

int main() {
    greet();
    return 0;
}
AFunction name: main
BFunction name: greet
CFunction name: __func__
DFunction name: (null)
Attempts:
2 left
💡 Hint
The __func__ macro expands to the name of the current function as a string.
🧠 Conceptual
expert
2:00remaining
Behavior of __LINE__ macro with macro expansion
Consider the following code. What is the output when compiled and run?
C
#include <stdio.h>

#define PRINT_LINE() printf("Line: %d\n", __LINE__)

int main() {
    PRINT_LINE();
    return 0;
}
ALine: 9
BLine: 5
CLine: 8
DLine: 7
Attempts:
2 left
💡 Hint
The __LINE__ macro expands to the line number where it appears after macro expansion.