#include #include using namespace std; int sum(int a, int b) // pass by value { return a+b; } int mySumRef(int &a, int &b) // pass by reference { return a + b; } void myPtrRef(int *a, int *b) // pass by reference { cout << "Sum is " << *a + *b << endl; } int* myIntReturn ( int a, int b) // returns a pointer { return &a; } int main() { int *myA = new int; int *myB = new int; *myA = 5; *myB = 10; myPtrRef(myA, myB); int c = sum(*myA, *myB); cout << "c = " << c << endl; int aa=5, bb=10; int d = mySumRef(aa, bb); cout << "d = " << d << endl; cout << endl << endl << endl << endl; int i; // holds a value int *ptr = NULL; // holds memory address i = 5; ptr = &i; cout << "i= " << &i << " ptr= " << ptr << endl; *ptr = 10; cout << "i= " << i << " ptr= " << *ptr << endl; // int *AnotherInt = new int; int *AnotherInt; // declaration AnotherInt = new int; // initalization *AnotherInt = 5; // assign AnotherInt to store 5 cout << "Addrss is= " << AnotherInt << " *AnotherInt= " << *AnotherInt << endl; char myChars[5]; myChars[0] = 'a'; myChars[1] = 'b'; char myChars2[5] = {'a'}; float myFloats[10] = { 1 }; int myInts[10]; for (i=0; i<10; i++) { myInts[i] = i; } // ALL of these do the same thing // they all create "strings" char name[] = "Barbara"; // char array string names = "Barbara"; // string class char *others = "Hecker"; // c-string cout << "others= " << others << endl; cout << "myInts Address= " << myInts << endl; cout << "myInts Value= " << *myInts << endl; others = name; cout << "Other is now= " << others << endl; return 0; }