Friday, March 9, 2018

C language with Mac: Hello World with Mac's Terminal

This post shows how to execute a hello world program in C with the following steps:

1. In terminal, create a C file called hello.c:

nano hello.c

2. Edit the hello.c file as:

#include <stdio.h>

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

3. In terminal, execute the file with:

cc hello.c
./a.out

Result:


References

How to run C program on Mac OS X using Terminal? (StackOverflow)
How to print Hello World in C on Mac (YouTube)
C++ with Mac: Hello World with Mac's Terminal
Matlab: Run Hello World files in C/C++ with MEX command

No comments:

Post a Comment