Print Character using Pointer and Array in C++


The program defines an array of 5 char pointers named names. The values of these pointers are initialized to point to string literals. The program then uses a for loop to iterate over the array and print each of the strings using the cout statement. Therefore, the output of the program is the 5 names "Arun", "Aswin", "Kanish", "Ram", and "Sam", each printed on a new line.

Source Code

#include<iostream>
using namespace std;
int main()
{
   char* names[5]={"Arun","Aswin","Kanish","Ram","Sam"};
   for(int i=0;i<5;i++)
   {
      std::cout<<names[i]<<std::endl;
   }
   return 0;
}
To download raw file Click Here

Output

Arun
Aswin
Kanish
Ram
Sam

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples