Skip to content

[C] Use gcc command to compile and print "Hello World"

Last Updated on 2021-04-29 by Clay

C Programming Language is one of the most common programming languages, and it can be seen in many Unix systems. Many systems and programs are also developed using C.

Therefore, the C language can be said to be a programming language with absolutely no harm when it is familiar to programmers.

The following execution environment uses operating system such as Linux and MacOS to compile and execute programs. If it is in the Windows environment, please refer to: MSYS2.


Print Hello World

If you start learning a new programming language, of course you start by printing out the Hello World string.

First you make a file named hello.c.

#include <stdio.h>


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


And use gcc command in terminal.

gcc hello.c

At this time, you should find a file named a.out under the current directory, which is our compiled executable file.

Use the following command to run it.

./a.out

Output:

Hello World


Supplementary note

#include <stdio.h>            // include information about standard library


int main() {                  // define a function named "main"
    printf("Hello World\n");  // statements of main to print this sequence of characters
    return 0;                 // It means this program end normally
}



References


Read More

1 thought on “[C] Use gcc command to compile and print "Hello World"”

  1. Really wish there were more C projects to get comfortable with the command line and making projects and connecting it all together, using some libraries etc.

    Pointers position always gets me, is it like this int* p, or is it int * p, or is it int *p.
    Same with address p = & a, or p = &a
    I just get confused with the way it looks rather than its function, *p is the pointer and holds what value is there, the & is to get the address of the pointer etc, p = &a, would be the address stored in p, something like that, it’s just the way it “looks” that bothers me, its positioning.

    But yeah, more Python type projects for C would really be handy, it’s always the basics, some command line usage with C projects, using libraries, nothing Major just some small projects seem hard to find without looking through lots of YT videos and websites.

    Nice site 😀

Leave a ReplyCancel reply

Exit mobile version