Can anybody write a small program that will compile in C but not C++

Pls. reply me if any body knows the answer.

there are lots of them.

int main()
{
   char *ptr = malloc(10);
  return 0;
}

The above will produce an error when compiled with c++ compilers.

And probably C ones, too, if you don't #include <stdlib.h> .

I like this one:

int main(void) {
    int is_c = 2//**/2
        -2;
}

although it compiles in C and C++. Try this:

struct class {};

Try doing this in both C and C++...It will compile in C but not in C++

int main()
{
 const int x;
 return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.