Cheat Sheet Prog
Cheat Sheet Prog
Cheat Sheet Prog
1
Typed constant expressions Preprocessor definitions (#define)
const double pi = 3.1415926; #define PI 3.14159
const char tab = '\t'; #define NEWLINE '\n'
int addition (int a, int Functions with no type. The value description
b) use of void
{ void printmessage (void) 0 The program was
int r; { successful
r=a+b; cout << "I'm a The program was
return r; function!"; successful (same
} }
EXIT_SUCCESS as above).
This value is
int main () Arguments passed by value
defined in
{ and by reference header <cstdlib>.
int z;
void duplicate (int& a) The program
z = addition (5,3);
{ a*=2;} failed.
cout << "The result is
int main () EXIT_FAILURE This value is
" << z;
{ int x =7; defined in
}
OUTPUT: The result is 8
duplicate (x);cout <<x; } header <cstdlib>.
OUTPUT: 14
Initializing arrays
int foo [5] = { 16, 2, int bar [5] = { 10, 20, 30 int bar [5] = { };
77, 40, 12071 }; };
myvar = 25;
foo = &myvar;
bar = myvar;
• & is the address-of operator, and can be read simply as "address of"
• * is the dereference operator, and can be read as "value pointed to by"
int main ()
{
int firstvalue = 5, secondvalue = 15;
int * p1, * p2;
(I)
http://courses.cs.vt.edu/~cs2605/spring08/