Using an array of pointers - C++ Data Type

C++ examples for Data Type:Array Pointer

Description

Using an array of pointers

Demo Code

#include <iostream>
int main()//  w ww  .  ja  v a 2  s .  c om
{
  const char* pstars[] { "Java", "HTML", "C++", "CSS", "C#", "Python", "Javascript", "Ruby" };
  int choice {};

  std::cout << "Pick  a lucky  star! Enter  a number  between 1 and "
            << sizeof(pstars) / sizeof(pstars[0]) << ": ";
  std::cin >> choice;

  if (choice >=1 && choice <= sizeof(pstars)/(sizeof pstars[0]))
  {
    std::cout << "Your lucky star is " << pstars[choice - 1] << std::endl;
  }
  else
  {
    std::cout << "Sorry, you haven't got a lucky star." << std::endl;
  }
}

Result


Related Tutorials