Can you think of 'a program' which gives 'different outputs for a C and a C++ compilers' (yet gives consistent output under the same language)?
This program produces 12
in C++ or C99, and 6
in C89:
#include <stdio.h>
int main()
{
int a = 12//**/2;
;
printf("%d\n", a);
return 0;
}
Incompatibilities between ISO C and ISO C++
A common example is sizeof('A')
, which is usually 4 in C but always 1 in C++, because character constants like 'A'
have the type int
in C but the type char
in C++:
#include <stdio.h>
int main(void)
{
printf("%d\n", sizeof('A'));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With