Professional Documents
Culture Documents
C++ source files (ASCII text) .cpp Programmer (you) C++ header files (ASCII text) .h readme (ASCII text)
// definition of function named main int main (int, char *[]) { cout << hello, world! << endl; return 0; }
What is #include <iostream> ? #include tells the precompiler to include a file Usually, we include header files
Contain declarations of structs, classes, functions
<iostream> is the C++ label for a standard header file for input and output streams
CSE 332: C++ program structure and development environment
argc
An integer with the number of parameters (>=1)
argv
An array of pointers to C-style character strings Its array-length is the value stored in argc The name of the program is kept in argv[0]
CSE 332: C++ program structure and development environment
int i = 0
Declares integer i (scope is the loop itself) Initializes i to hold value 0 (not an assignment!)
i < argc
Tests whether or not were still inside the array! Reading/writing memory we dont own can crash the program (if were really lucky!)
++i
increments the array position (why prefix?)
CSE 332: C++ program structure and development environment
{cout << argv[i] << endl;} Body of the for loop I strongly prefer to use braces with for, if, while, etc., even w/ single-statement body
Avoids maintenance errors when adding/modifying code Ensures semantics/indentation say same thing
argv[i]
An example of array indexing Specifies ith position from start of argv
CSE 332: C++ program structure and development environment
An
IDE
WebCAT E-mail Eclipse Visual Studio
debugger
make
make utility
turnin/checkin
Programmer (you)
precompiler compiler
gcc, etc.
compiler
link
linker executable program