Welcome to C

Typical C Workflow

  1. Edit files with emacs or vim.
  2. Compile using a GNU C compier (abbreviated as "gcc") to compile, link, and create executable.
  3. Run the executable file.

It's better to code incrementally as you will have a better time debugging.

Compiling

Step 1: Preprocessor

Step 2: Compiler

Step 3: Linker

Understanding Hello World program

// hello_world.c:
#include<stdio.h>

// Print "Hello, world!" followed by a newline and exit
int main(void) {
	printf("Hello, world!\n");
	return 0;
}

Compilation and Execution

To compile hello_world.c and link to give executable file:

gcc -std=c99 -Wall -Wextra -pedantic hello_world.c

To run executable file named a.out:

./a.out

Multiple Copies of Code

To "snapshot" code is making a copy. Frequent "snapshots" is bad because it's hard to remember the relationship of copies, wastes space, and is difficult for team members to track the latest version of each file.

Git uses a repository ("repo") to store all versions of all project files. A repo (master/origin) can be local (on your computer) or remote (e.g., on bitbucket.org or github.com).