Wednesday, July 12, 2006

C or C++

Write a program that will print "C" if compiled as an (ANSI) C program, and "C++" if compiled as a C++ program.

$cat a.c
#include

int
main ()
{
char ch[][5]={"C++","C"};
printf ("%s \n",ch[( 2 //*
/ 2) -1] // */ 1) -1]
);
return 0;
}

$cc a.c ; ./a.out ????
$cc -ansi a.c ; ./a.out ????
Contributed by -KC

No comments: