In that webinar

what is the difference between xptr and *xptr . Pls explain in detail @tarunluthra

@Nikhil-Aggarwal-2320066674901389
Consider this code snippet

int main() {
int x = 10 ;
int *xptr = &x ;
cout << xptr << endl ;
cout << &x << endl;
cout << x << endl ;
cout << *xptr << endl;

return 0 ;
}

Let’s proceed line by line

int x = 10 ;
First we declare a variable x having type int with value 10.

int *xptr = &x ;
Then we make a pointer variable and assign it the address of x. That is , declaring a pointer with * makes that a special variable , a pointer variable. A pointer variable does not store normal int data but rather the address to a memory location. Since all data is stored in memory at some memory location , the variable x we declared earlier too must be at some location.
We can obtain the address of this variable using & sign . “&x” gives us the address of the memory location where x is stored and we store the address returned by &x in a pointer variable we just declared named “xptr” .

cout << xptr << endl ;
As xptr is a pointer variable which stores the memory location and not the data , printing the data in xptr would simply print the address location where x is stored. Note that this value will be different for every computer and might even vary everytime you run the program as storage location may change in the computer for x.

cout << &x << endl;
As discussed earlier , &x gives us the address where x is stored so this would give us the exact same result as the previous statement.

cout << x << endl ;
This is a simply cout statement which will print 10 … the data stored in x variable.

cout << *xptr << endl;
xptr has the address of x variable. * (asterisk/star operator) can be used to dereference pointer variables , i.e. *xptr will return the data at the memory location stored in this variable .
What the * operator does is , it reads the address stored in the pointer variable , goes to that memory location , and returns the data at that memory location . So this would print 10.
Since xptr has memory location of x , *xptr refers to x.

Think of deference operator as a transpose of & , like + and - are transpose of each other in maths .
xptr = &x ;
*xptr = x ;

cout << *xptr << endl ; statement prints 10 which is the data in x.