Skip to main content

The C Programming Language

C has the power of assembly language and the convenience of … assembly language. -- Dennis Ritchie

Mac already has gcc (the compiler we need for C) and debugging tools installed for C so we just need to setup the IDE.

Configure your IDE

tip

While you can probably survive your C class without touching Terminal, we recommend using it! It not only gives you a better understanding of how a computer program is created, but also prepares you for your further modules, which almost certainly will require familiarity with the shell.

Let's use VS Code to create a simple C program!

  1. Open VS Code and create an empty file called main.c. This will be our C code source file. Such files have the .c extension!

  2. Paste the following snippet and save the file:

    #include <stdio.h>

    int main() {
    printf("Hello, World!\n");
    return 0;
    }
  3. Now, you need to compile your code. Let's see how we can do it from Terminal. Open Terminal in the same directory as the main.c file and run the following command: bash gcc -o main_executable main.c This command will invoke gcc - compiler of the C code, compile the file called main.c and output a binary file named main_executable.

  4. To run your program, simply type:

    ./main_executable

    which should produce

    > Hello, World!

Well done, Terminal is for Turbo cool people! 🎉 🥳