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?

Recommended Answers

All 2 Replies

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...

#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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.