










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!











By Anam Javaid COMSATS University Islamabad, Wah Campus
Call by Value
Call by Reference
Difference in Reference variable and pointer variable 1.A pointer can be re-assigned while reference cannot, and must be assigned at initialization only.
int main() { int x = 5; int y = 6; int *p; p = &x; p = &y; // 1. Pointer reintialization allowed int &r = x; // &r = y; // 1. Compile Error r = y; // 1. x value becomes 6 p = NULL; // &r = NULL; // 2. Compile Error p++; // 3. Points to next memory location r++; // 3. x values becomes 7 cout << &p << " " << &x << endl; // 4. Different address cout << &r << " " << &x << endl; // 4. Same address cout << p << endl; // 6. Prints the address cout << r << endl; // 6. Print the value of x return 0; }