Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

tutorial cbasics

Tianshu Huang edited this page Oct 7, 2018 · 6 revisions

What is C?

C is a programming language. This means that in order to run C code, you must first compile it into machine code (code made from 1s and 0s).

Hello, World!

If you've never written a C program before, as is custom, follow this example:

touch hello.c
emacs hello.c    # or other text editor

In your text editor:

#include <stdio.h>
int main() {
    printf("Hello World!\n");
}

Finally, compile and run:

gcc hello.c
./a.out

Parts of a C program

/* This is a comment. Comments are ignored by the compiler. */
// This is also a comment.
/*
 * Comments made with "/*" can span multiple lines
 * like this.
 */

// Includes (this will be covered later)
#include <stdio.h>

// Main function
// All C programs must contain a 'int main' block
int main() {                     // Logical blocks in C are wrapped with curly braces
    printf("Hello World!\n");    // All C statements end with semicolons
                                 // The compiler will be very angry if you forget one
}
Clone this wiki locally