-
C or C++ code
I posted this code on another forum and was blasted because it is supposedly not C, but C++. Can someone please show me wherein this code is not legitimate C code? I dont' see it.
Code:
#include <stdio.h>
int main(unsigned char *argv[], int argc)
{
//declare two integers and load them with unique values
int x = 5;
int y = 3;
//report the pre-algorithm values to the user
printf("before:\n");
printf("x = %d\n", x);
printf("y = %d\n", y);
//the 1st variable now holds the sum of both integers (x = 5 + 3 or x = 8)
x = x + y;
//the 2nd variable now holds the result of subtracting its original value from the sum
//(y = 8 - 3 or y = 5)
y = x - y;
//the 1st variable now holds the result of subtracting its 2nd variable from the sum
//(x = 8 - 5 or x = 3)
x = x - y;
//report the post-algorithm values to the user
printf("after:\n");
printf("x = %d\n", x);
printf("y = %d\n", y);
}
Thanks in advance.
-
It's C99, except the parameters of main are the wrong way around. It should be one of:
Code:
int main(int argc, char *argv[])
int main(void)
It would be valid C89 (more common) if:
(a) you removed the C99/C++ style // comments, or replaced them with /* */ comments.
(b) you added an explicit return 0; on the end of the main function.