Jump to: navigation, search

Week 2

1,516 bytes added, 13:44, 20 May 2010
no edit summary
A function must have one point of entry and one point of exit. Only one return statement per function.
<u>The Include Statement</u>
''#include <stdio.h>''
The hash tag (#) tells the compiler how to do things '''BEFORE''' compilation. The #include keyword brings in the code from inside <stdio.h> Header files are usually definitions of functions, classes, templates, etc. <u>The Define Statement</u> A #define statement is a simple search and replace in the current file. ''#define SUM a+b'' ''printf("%d\n", SUM*2);'' This will print 50, not 60. It replaces SUM with a+b then operator precedence allows it to multiply first before addition.  <u>Macros</u>
The hash tag ''#define SUM(x, y) (x+y)'' ''printf("%d\n", SUM(i, j)*2);'' ''printf("%d\n", SUM(a, b)*2);'' Those two statements will have ''i+j'' and ''a+b'' instead. Why not replace SUM(a, b) to a+b in the code instead of telling SUM to do it for you before compilation? You might need to change several different things. Could also make it easier to manage code? Another example: ''#define MAX(x, y) ((x)>(y)?(x) tells :(y))'' <u>Conditional Compilation</u> With conditional compilation you can tell the compiler how to do things only compile a section of the code. ''#define COMPINT 1''''#define COMPDOUBLE 2''''#define COMP COMPINT'' In the code: ''#ifdef COMP == COMPINT'' ''Code'' ''Code'' ''Code''''#endif'' ''#ifdef COMP == COMPDOUBLE'' ''Code'' ''Code'' ''Code''''#else'' ''Code'' ''Code'' ''Code'''BEFORE'#endif'' compilation It will only compile the first if statement and the else statement.  Thursday May 20, 2010 Cursor Movement Low-Level Header Files:
The include word brings in the code from inside <stdio'''Platforms: Headers: '''BCC: conio.hVCC: windows.h and conio.hLinux: ncurses.hUnix: curses.h>

Navigation menu