Original Post
whats a pointer
#include <iostream>using namespace std;void f(int* p) { //the function f() takes a pointer to a type int cout << "p = " << p << endl; cout << "*p = " << *p << endl; //this is the dereferencing *p = 5; //this is the part where the pionter is used to modify x cout << "p = " << p << endl; }int main() { int x = 47; cout << "x = " << x << endl; cout << "&x = " << &x << endl; //this displays the address of variable x f(&x); //the address to variable x is passed to function f() /* you should read the above function definition now, and replace p with "the address of x" and *p with "the value of x" */ cout << "x = " << x << endl; //the result}This topic has been locked by a moderator. New replies are not allowed.
GameDev.net uses cookies to ensure you have the best experience on our platform. Learn more