Need to write a C program. If it is run in the C language compiler, the program should print "C". If it is run in the compiler C++, it should print "C++".
Preprocessor directives can not be used.
In head comes only to compare the size of any character with the char
size like:
sizeof(char)==sizeof('a')
Here how it works:
// C code:
#include <stdio.h>
int main()
{
printf("%s", (sizeof(char)==sizeof('a') ? "C++" : "C"));
return 0;
}
Output: C
// C++ code:
#include <stdio.h>
int main()
{
printf("%s", (sizeof(char)==sizeof('a') ? "C++" : "C"));
return 0;
}
Output: C++
There, a better way?