marți, 6 decembrie 2016

C++ Pointers Example

C++ > Pointers

Syntax:

type * name;


A variable which stores the address of another variable is called a pointer.

Pointers point to the variable whose address they store.

Example


#include "stdafx.h"

int main()
{
       int var = 25;
       int *adr = &var;
       // *adr = 25
       // adr   = 0x0042fc1c

       *adr = 30;
       // var = 30

    return 0;
}