Microsoft PowerPoint - cpptutorial.ppt
Short Description
C++ Tutorial. by Rob Jagnow. for MIT’s 6.837 Introduction. to Comptuer Graphics. Overview. . Pointers. . Arrays and strings. . Parameter passing …
Website: www.cs.rpi.edu | Filesize: 84kb
Content
C++ Tutorial
by Rob Jagnow
for MIT’s 6.837 Introduction
to Comptuer Graphics
Overview
?Pointers
?Arrays and strings
?Parameter passing
?Class basics
?Constructors & destructors
?Class Hierarchy
?Virtual Functions
?Coding tips
?Advanced topics
Pointers
int *intPtr;
intPtr = new int;
*intPtr = 6837;
delete intPtr;
int otherVal = 5;
intPtr = &otherVal;
Create a pointer
Allocate memory
Set value at given address
Change intPtr to point to
a new location
*intPtr 6837
intPtr 0×0050
*intPtr 5
intPtr 0×0054
otherVal
&otherVal
Deallocate memory
Arrays
int intArray[10];
intArray[0] = 6837;
int *intArray;
intArray = new int[10];
intArray[0] = 6837;
…
delete[] intArray;
Stack allocation
Heap allocation
Strings
char myString[20];
strcpy(myString, “Hello World”);
myString[0] = ‘H’;
myString[1] = ‘i’;
myString[2] = ‘