ch1-Hello (Compile and run a program in C)

Chapter_1 Exercise_1-1







hello.c     K&R, p.6         download


#include <stdio.h> // no semicolon after directive

int main()
{
printf("Hello, world!\n"); // 2 spaces indentation
// normal return value for main():
// return 0; // 0 signals no errors
}
/*
gcc -E hello.c // preprocessing
gcc hello.c // compiling
./a.out // running the program
a.out // running the program
Hello, world! // output
gcc hello.c -o hello // specify name of executable
./hello // run program
hello // run program
Hello, world!
*/





Notes:

When running programs, do not write the comments in the terminal window, for instance, write
gcc hello.c
./a.out


"." is the current directory. Both
program
and
./program
run the program "program" from the current directory.









Chapter_1 BACK_TO_TOP Exercise_1-1



Comments

Popular posts from this blog

Contents

Blogger Page Margins in Contempo