final cheat sheet

final cheat sheet - void func(int &x)//Pass the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
static_cast<double>( name of thing ) Arrays int a[100]; //declaration int a[10] = {1,2,3,4,5} //the rest of the 10 are zeros if you change the values of an array with a function, it changes in main function too passing function: int positionMax( string a[], int n) calling the function: int x = positionMax (a, 15); CStrings when creating a c-string, you need to leave room for one ‘\0’ char s[] = “hello”; isPrint() ----- is it a printable character? cin.getline( array name, int size ) //C getline(cin,s); //C++ Pointers double x; double *p; p = &x; *p = 5.0;//asterisk is called dereference marker if you do cout << arr it’ll cout 0012FD80 same thing as cout << &arr[0]; *(arr+1) == arr[1]; int *p; p = arr; p = arr + 5; p = & arr[5]; The above all work. If they have * in front of them, none of them will work.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: void func(int &x)//Pass the argument by reference p = &x // Get x's location (address) in memory AS A PARAMETER TO A FUNCTION, double a means the same as double* a &a[i] - & a[j] ==> i-j DONT HAVE UNINITIALIZED POINTERS! for dynamic memory, int *p = new int; delete p; doub = new int*[DIM]; //this sets up an array of pointers doub[i] = new int[DIM]; //array of integers for (int i = 0; i < DIM; i++) { delete doub[i]; delete doub2[i]; } delete doub; for (int i = 0; i< n; i++) { char gr = students[i].grade; if(gr != 'F') total + = 4 - (gr - 'A'); // because A is 65, B is 66, etc. } Class and Struct class defaults private, struct defaults public Dot operator versus arrow operator: object dot member pointer arrow member...
View Full Document

This note was uploaded on 11/10/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 2

final cheat sheet - void func(int &x)//Pass the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online