Mutató equivalencia C++

pmovie->title     ====     (*pmovie).title

NO EQUIVALENT TO:

*pmovie.title  ====   *(pmovie.title)
Expression What is evaluated Equivalent
a.b Member b of object a
a->b Member b of object pointed by a (*a).b
*a.b Value pointed by member b of object a *(a.b)
expression can be read as
*x pointed by x
&x address of x
x.y member y of object x
x->y member y of object pointed by x
(*x).y member y of object pointed by x (equivalent to the previous one)
x[0] first object pointed by x
x[1] second object pointed by x
x[n] (n+1)th object pointed by x

Mutató függvényre C++

// pointer to functions http://www.cplusplus.com/doc/tutorial/pointers/
#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, int (*functocall)(int,int))
{
  int g;
  g = (*functocall)(x,y);
  return (g);
}

int main ()
{
  int m,n;
  int (*minus)(int,int) = subtraction;

  m = operation (7, 5, addition);
  n = operation (20, m, minus);
  cout <<n;
  return 0;
}

Mutatók és tömbök C++

// more pointers source: http://www.cplusplus.com/doc/tutorial/pointers/
#include <iostream>
using namespace std;

int main ()
{
  int numbers[5];
  int * p;
  p = numbers;  *p = 10;
  p++;  *p = 20;
  p = &numbers[2];  *p = 30;
  p = numbers + 3;  *p = 40;
  p = numbers;  *(p+4) = 50;
  for (int n=0; n<5; n++)
    cout << numbers[n] << ", ";
  return 0;
}
10, 20, 30, 40, 50, 

Mutató és referencia maszlag C++

void duplicate(int& a, int&b){
  a*=2;
  b*=2;
}
void pointer_duplicate(int* a,int* b){
  // *a=(*a)+(*a)
  // *b=(*b)+(*b)
duplicate(*a, *b); //Ugyanaz mint a 2 kikommentezett
}
int main(){
  int a=2;int b (3);
  int* e; int* f;
  e=new int(3); f=new int(4);
  duplicate(a,b);
  duplicate(*e,*f);
  pointer_duplicate(&a,&b);
  pointer_duplicate(e,f);
}