Tutorial :Write a program that will print “C” if compiled as an (ANSI) C program, and “C++” if compiled as a C++ program



Question:

Taken from http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml

It looks very compiler specific to me. Don't know where to look for?


Solution:1

Simple enough.

#include <stdio.h>  int main(int argc, char ** argv) {  #ifdef __cplusplus  printf("C++\n");  #else  printf("C\n");  





        
Previous
Next Post »