1.1 用gcc编译: $ gcc -Wall -g main.c -o gcc_compile_c main.c: In function 'main': main.c:20: warning: implicit declaration of function 'add' main.c:23: warning: 'return' with no value, in function returning non-void
运行: $ ./gcc_compile_c 4 + 3 = 7
1.2. 用g++编译 代码如上所示 $ g++ -Wall -g main.c -o g++_compile_c main.c: In function 'int main(int, char**)': main.c:20: error: 'add' was not declared in this scope main.c:23: error: return-statement with no value, in function returning 'int'
改成如下: #include
int add(int a, int b) { return (a + b); }
int main(int argc, char* argv[]) { int a = 4; int b = 3; int ret = 0;