Thursday, November 14, 2013

Hello World using C on Raspberry Pi

The post show how to use the editor nano to create a C's source code of "Hello World", then compile with gcc, and run it. All tools, nano and gcc, are come with Raspbian.

- Create a text file helloworld.c with nano, Ctrl-X to Exit and save the file.
$ nano helloworld.c

- Enter the code:
#include <stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}

- Compile the code and set output as helloworld
$ gcc -o helloworld helloworld.c

- Run the generated helloworld
$ ./helloworld

The words "Hello World" will be printed.

No comments: