|
Tue, Apr 22, 2008
![[Link]](http://geekblog.oneandoneis2.org/img/chain_link.gif)
Right. It's been ages since I tried learning any C, so I'm scanning back through the K&R pages I already did as a refresher. I'm jotting down the things to remember as I do so in this post, so it probably won't be all that interesting, but what the Hell, it's my blog ![]()
Right.
The obligatory start:
#include <stdio.h> This is an instruction to the compiler to read the header file stdio.h, in which functions are declared so you don't have to redundantly declare them in every program you ever use.
int main() Every program has to have at least one function, the main() function. The 'int' tells the program that the function should return an integer. It isn't really necessary for main() to do this, but what the hell.
{ Brackets are used to define the start and finish of a function.
printf("Hello, world\n"); Printf() is a function, declared in stdio.h. "Hello, world\n" is the string you want it to print, with \n being the carriage-return character. The semi-colon at the end tells the compiler where the statement ends: Unlike, say, python, carriage returns don't signify a new statement in C
return 0; This is where we tell the function to return an integer, as we already defined main() as an integer-returning function. It doesn't have to be 0, it just has to be a number.
} And of course, we have to close brackets after we open them...
Well, that was fun, wasn't it? :o)
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | > >> | |||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||