Difference between revisions of "C programming quick start"
From thelinuxwiki
(Created page with " '''#include <stdio.h>''' The #include is a "preprocessor" directive that tells the compiler to put code from the header called stdio.h into our program before actually crea...") |
|||
Line 25: | Line 25: | ||
gcc hello.c -o hello | gcc hello.c -o hello | ||
− | ''' | + | '''run hello world and check exit status of last command''' |
$ '''./hello''' | $ '''./hello''' |
Revision as of 20:43, 10 July 2014
#include <stdio.h>
The #include is a "preprocessor" directive that tells the compiler to put code from the header called stdio.h into our program before actually creating the executable
int main() { }
Main body of program. Returns integer exit status to O.S. after execution. 0 = success, non zero is an error message.
hello world example
- include <stdio.h>
int main() {
printf( "Hello world!\n" ); printf( "(hit enter to end)\n" ); getchar(); return 0;
}
compiling with gcc
gcc hello.c -o hello
run hello world and check exit status of last command
$ ./hello Hello world! (hit enter to end)
$ echo $? 0 $ ./hello Hello world! (hit enter to end) ^C $ echo $? 130