    6 Pages
English

# Super Study Sheets _9

Learn all about the services we offer Description

• expression écrite
GLOBAL REGENTS SUPER STUDY SHEETS _9 - PAGE 1 of 6 THIS IS GLOBAL REGENTS SUPER STUDY SHEET NUMBER NINE THE TOPICS OF STUDY IN THIS PACKET ARE: • THE RENAISSANCE - This topic is divided into four parts. This packet covers all four: 1) What Happened During the Renaissance? 2) Why Did the Renaissance begin in Italy? 3) Niccolò Machiavelli 4) The Printing Press • THE PROTESTANT REFORMATION AND THE COUNTER (CATHOLIC) REFORMATION • THE SCIENTIFIC REVOLUTION • THE SPANISH GOLDEN AGE
• protestant reformation
• reason for the success
• value of human reasoning
• super study sheets
• western europe
• enlightenment ideas of natural law
• ideas
• scientific revolution
• church
• power

Subjects

##### Greece

Informations

C++ Pointers and Strings
C++ Spring 2000Arrays
Pointers A pointer is a variableMEMORY Address that holds theaddress 0 of something else.1 2 int foo;foo 123 3 4 int *x; 5 foo = 123; 81345 x = &foo;x 3 81346 81347 C++ Spring 2000Arrays
1
int *x;  xis a pointer to an integer.  Youcan use the integer x points to in a C++ expression like this: “the int x points to” y = *x + 17;
*x = *x +1;
C++ Spring 2000Arrays
3
1
&foo In C++ you can get theaddressof a variable with the “&” operator. MEMORY int foo; Address 0 1 foo = 123;2 x = &foo;foo 123 3 4 5 means “the address of foo” &foo
C++ Spring 2000Arrays
Assigning a value to a dere erencedpointer A pointer must have a value before you can dereferenceit (follow the pointer).
int *x; *x=3;
int foo; int *x; x = &foo; *x=3;
C++ Spring 2000Arrays
4
5
Pointers to anything some x int int *x; int **y;some some y *intint
double *z;
some z double
C++ Spring 2000Arrays
6
2
Pointers and Arrays
 Anarray name is basically aconstpointer.  Youcan use the [] operator with a pointer:
int *x; is “the address ofint a;x a x = &a; for (inti=0;i<3;i++) x[i]++; is the same as x[i] a[i+2] C++ Spring 2000Arrays 7
Pointer arithmetic  Integermath operations can be used with pointers.  Ifyou increment a pointer, it will be increased by the size of whatever it points to. int *ptr = a; *(ptr+2) *(ptr+4) *ptr
a a a a a int a; C++ Spring 2000Arrays
printing an array
void print_array(int a[], int len) { for (int i=0;i<len;i++) cout << "[" << i << "] = " << a[i] << endl; }
void print_array(int *a, int len) { for (int i=0;i<len;i++) cout << "[" << i << "] = " << *a++ << endl; }
C++ Spring 2000Arrays
8
9
3
Passing pointers as parameters
void swap( int *x, int *y) { int tmp;
tmp = *x; *x = *y; *y = tmp; }
C++ Spring 2000Arrays
Pointer Parameters  Pointersare passed by value (the value of a pointer is the address it holds).
 Ifwe change what the pointer points to the caller will see the change.
10
 Ifwe change the pointer itself, the caller won't see the change (we get a copy of the pointer) C++ Spring 2000Arrays 11
C++ strings  Astringis anull terminatedarray of characters. – null terminated means there is a character at the end of the the array that has the value 0 (null).  Pointersare often used with strings: char *msg = “RPI”; msg 'R' 'P' 'I'0 C++ Spring 2000Arrays 12
4
String Manipulation Functions
 C++includes a library of string handling functions:
char * strcpy(char *dst, const char *src) char * strcat(char *dst, const char *src) lots more!
C++ Spring 2000Arrays
13
String Example - Count the chars
int count_string( char *s) { int n=0; while (*s) { n++; s++; } return(n); }
C++ Spring 2000Arrays
Another way int count_string( char *s) { char *ptr = s;  while (*ptr) { ptr++; } return(ptr - s); }
C++ Spring 2000Arrays
14
15
5
Exercises (for those so inclined)
 Write strcpy  Writea function that compares 2 strings and returns ifthey are the same string, true if they are not. false  Writea function that removes all spaces from a string.
C++ Spring 2000Arrays
16
6