

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















int* iPtr; double * xPtr; char *c; float *x, *y;
int* iPtr;
iPtr = &i;
int iCopy = *iPtr; // now iCopy equals i
void passPointer(int* iPtr){ *iPtr += 2; // note iPtr on left! } ... int i = 3; int iPtr = &i; passPointer(iPtr); cout << "i = " << i << endl; // prints i = 5 passPointer(&i); // equivalent to above cout << "i = " << i << endl; // prints i = 7
passReference(j); cout << "i = " << i << endl; // prints i = 9 int i = 3; int& j = i; // j is a reference variable j = 7; cout << "i = " << i << endl; // prints i = 7 void passReference(int& i){ i += 2; }
char aString[] = "hello"; // inserts \0 at end
char* strcpy(char* target, const char* source);
#include
class TwoVector { public: TwoVector(); TwoVector(double x, double y); double x(); double y(); double r(); double theta(); void setX(double x); void setY(double y); void setR(double r); void setTheta(double theta); private: double m_x; double m_y; };
#ifndef TWOVECTOR_H #define TWOVECTOR_H class TwoVector { public: ... private: ... }; #endif
private: double m_x; double m_y;
public: TwoVector(); TwoVector(double x, double y);
TwoVector::TwoVector() { m_x = 0; m_y = 0; } TwoVector::TwoVector(double x, double y) { m_x = x; m_y = y; }
TwoVector w = v;
TwoVector v(1.5, 3.7); // creates an object v double vX = v.x(); cout << "vX = " << vX << endl; // prints vX = 1. ...
double vX = v.m_x;