#include <stdio.h>
/* Hello World program written in C. */
int main(void) {
printf("Hello, World!\n"); // output some text
return 0; // 0 means success
}
Allow to include
code declared elsewhere
#include <stdio.h>
/* Hello World program written in C. */
int main(void) {
printf("Hello, World!\n"); // output some text
return 0; // 0 means success
}
// single line comment
int x = 5; // comments can be added at the end of a line
/*
* multiline comment
* ...
*/
Removed by the preprocessor
Serves a special purpose in C programs:
program execution begins with main(.)
#include <stdio.h>
/* Hello World program written in C. */
int main(void) {
printf("Hello, World!\n"); // output some text
return 0; // 0 means success
}
Indicate success (0
) or a failure code to the calling
operating system shell
#include <stdio.h>
/* Hello World program written in C. */
int main(void) {
printf("Hello, World!\n"); // output some text
return 0; // 0 means success
}
Executable program files are created from readable source code.
main.c
executable
Creating a C executable is a four step process.
Download hello.c
By default, all four stages (preprocessor, compiler, assembler
and linker)
are done
clang hello.c # or ` hello.c`
./a.out
Provide a name for the created executable (instead of the default
a.out
clang hello.c -o hello
./hello
Compilation can be done with either clang
or
.
clang $INFILE -o $PROGRAM_NAME
$INFILE -o $PROGRAM_NAME
Stop after preprocessor and send output to stdout
clang -E hello.c
Creates assembler files (usually *.s
)
clang -S hello.c
*.o
filesmain(.)
main(.)
clang -c hello.c
clang -o hello hello.o