0

when i try the code below :

#include <iostream>

using namespace std;


int a = 3;
int b = 4;
int c = 5;
int * pA = &a;
int * pB = &b;
int * pC = &c;

int * abc[] = {pA,pB,pC};

int main()
{

 cout << abc[*pA] << endl;

  return 0;
}

i get the following output :

20000e50

What does that mean?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by BevoX
0

You are trying to print an uninitialized and unexistent abc[3] element of abc array of pointers to int...
It's the hexadecimal representation of this value...

0
#include <iostream>

using namespace std;

int a = 3;
int b = 4;
int c = 5;
int * pA = &a;
int * pB = &b;
int * pC = &c;

int *abc[] =  { pA, pB, pC };

int main()
{
     cout <<  *abc[0] << endl;
     return 0;
}

Give the array the index number of the element, and then dereference it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.