C++ array of pointers

You can create an array that it elements are pointers by placing the * sign in front of the array name.

#include <iostream>
#include <conio.h>
using namespace std;


int main(){
  
   int *array_pointer[3];//declare array of pointers
   //this array is to store 3 pointers
   int x,y,z;
   array_pointer[0]=&x;//first pointer points to x
   array_pointer[1]=&y;//second pointer points to y
   array_pointer[2]=&z;//third pointer points to z
   //use pointers to assign values to variable x,y, and z
   for(int i=0;i<3;i++)
        *array_pointer[i]=i*10;
   cout<<x<<"\t"<<y<<"\t"<<z;
   getch();
   return 0;
}

Posted by: Ly Meng | post date: 01-26-2013 | Subject: C++ Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.