How to write your first program in C using the classic Hello World method

CS50 Lecture by Brian Kernighan · 52:51 · Video: CS50 · Watch at the source

In short: Brian Kernighan, a legendary figure in computer science, famously popularized the Hello World program. By writing this simple code, you begin to build the essential muscle memory required for programming. Follow this guide to set up your environment, write your first lines of C, and verify your code works correctly.

The Hello World program is a foundational rite of passage for programmers, implemented in hundreds of languages worldwide. Its simplicity belies its importance as a starting point for understanding how source code is transformed into machine code. Brian Kernighan, a professor at Princeton University and a co-author of the seminal K&R book, has long championed this approach to learning. In 2010, he returned to Harvard University's CS50 course to discuss numeric self-defense, reflecting his deep involvement in the intellectual enterprise of computer science education.

To begin, you must organize your workspace by creating a directory and a specific file. In a terminal environment, you create a folder named world and then generate a file called hello.c. Within this file, you write the C code that instructs the computer to print the phrase hello, world to the screen. This process is not merely about the output; it is about the physical act of typing the syntax, which helps the brain develop the necessary muscle memory for future coding tasks.

Once the code is written, the next phase involves compilation and testing. You use a compiler to translate your source code into executable machine code. If errors occur, tools like help50 provide guidance on how to resolve them. After successful compilation, you can run the program directly. Further validation is possible through automated tools like check50, which verifies correctness, and style50, which offers suggestions to improve the readability and structure of your code. This systematic approach ensures that even the simplest program is built upon a solid foundation of testing and refinement.

Opens the Intellect+ feed with this card first. Swipe up for the next one.

Sources

To cite this card, link to https://intellectplus.co.uk/app/technology-cs50-lecture-by-brian-kernighan.

How we source, check and correct cards: Editorial standards.

General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.

Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?

Related

Finding something worth knowing…