This repository was archived by the owner on Jun 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
tutorial cbasics
Tianshu Huang edited this page Oct 7, 2018
·
6 revisions
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).
If you've never written a C program before, as is custom, follow this example:
touch hello.c
emacs hello.c # or other text editorIn your text editor:
#include <stdio.h>
int main() {
printf("Hello World!\n");
}Finally, compile and run:
gcc hello.c
./a.out/* 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
}