Week 1
Every C program you run will have a main() function, which will look something like:
int main(void){
// more code here
return 0;
}
Everything inside the curly braces { } is in the main function. To make it easier to read, every time we come across a pair of curly braces all the code inside is indented.
Another thing your code should always have is comment. Each file should have a comment up the top with who wrote it, the date and what the code in that file does. As your code becomes more complex you will also want to write comments as you go.
// Author: Andrew Taylor (andrewt@unsw.edu.au)
// Date created: January 2018
// A very simple C program
#include <stdio.h>
int main(void) {
printf("I love COMP1511!\n");
return 0;
}
printf() stands for "print formatted", and is how we output text in C. Note here the special character \n, which is a newline. You can open the manual page for printf by writing man printf in your terminal to see other special characters in C. These are called escape sequences, and backslash \ is the escape character.