CS 201 - 8/26/2014 Programming Basics - Chapter 1 Source code files: text files with the code C program xxxx.c C++ program xxxx.cpp CS201 will not cover objects Create an object file from the source code file object files xxxx.o Executable file On windows: xxxx.exe On Linux: xxxx Default Linux: a.out Compilation process 1. Preprocessor 2. Compiliation - create the object files 3. Linking - create the executable files Preprocessor items: #define #include #ifdef #ifndef #endif Mostly for libraries #include /* C style library */ #include /* C++ style library */ imports the function signatures of the library operations function signatures - name of the function - number, type and order of the parameters - return type int max (int p1, int p2) { ... return z; } int main () { int a,b,c a = max (b, c); } ========================= int max (int, int); /* prototype or forward declaration */ int main () { int a,b,c a = max (b, c); } int max (int p1, int p2) { ... return z; } ---------------------------- #define - C style constant #define MAX 1000 for (i = 0 ; i < MAX ; i++) { .... } In C++ #define was replaced with const const int MAX = 1000; #define MAX(x,y) x>y?x:y a = MAX(b,c); a = b>c ? b : c ; b = 10; c = 3; a = 2 * MAX(b+1,c+2) a = 2* b+1>c+2 ? b+1 : c+2; #define SIX 1+5 #define NINE 8+1 SIX * NINE 1 + 5 * 8 + 1 ----------------------------------- #ifdef #ifndef #endif ------------------------------------------- C pointers - first item parameter passing pass-by-value pass-by-reference int main() { int a; a = 10; funct1 (a); funct2 (&a); } ---------------- funct1 ( int p1) { p1 = p1 + 5; } ---------------- funct2 ( int* p1) /* pass by address */ { printf ("%d", *p1); *p1 = *p1 + 5; }