Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#include <stdio.h>
#define swap(t,x,y) \
( t type = x; x = y; y = type; )
int main()
{
int x, y;
x = 2, y = 10;
swap(int, x, y);
printf("%d %d\n", x, y);
return 0;
}
C++ is more "complicated" than C because it can do things in a line or three of code that in C either requires a large number of code lines or is impossible.
#include <iostream> // cout, endl
#include <algorithm> // swap
usingnamespace std;
int main()
{
int x = 2;
int y = 10;
swap(x,y);
cout << x << ' ' << y << endl;
}
I always recommend the simplest correct solution to a problem. Don't be turned off from an entire language just because it is possible to write horrifyingly complex code with it. Personally I am fearful of having to work in the limitations of C.
I'm also somewhat fearful of having to work within the limitations of most anything other than C++ since that's what I've always used (FYI I mean speed limitations mainly). I also don't get why people use C when you can compile C as C++ and then when you have to additional features of C++, you'll just find so many simplification and optimisations that can be done easily.