#include <stdlib.h>

int main()
    int *ptr[5];
      int a[] = {1,2,3,4,5};                 //declaring and integer array 
      char b[] = {'a','b','c','d','e'};      //declaring and Character array 
         *ptr=a;                          //assign values of integer array to integer pointer array

         for(int i=0;i<5;i++)                   //by looping, Print values of array a, pointing to pointer
              cout<<"A["<< i+1 <<"] : " << *ptr+i <<endl;

       int *pntr=(int*)b;                  //Assign values of character array to poniter array of int type               


i want the output like this...

A[1]: 97
A[2]: 98
A[3]: 99
A[4]: 100
A[5]: 101

5 Years
Discussion Span
Last Post by Schol-R-LEA

why no one is giving reponse??? atleast there should be some response...


Such a hero waiting for full 7 minutes.
Please teach me how to be so patient .

You know, I thought that if char * points somewhere it points to 1 byte
and an int * points to 4 bytes, so I guess Cout << is going to be mad.

Edited by Despairy


alright, type this in your code and see what happens:

int charEquivalent = 'a';
cout << charEquivalent;

Bottom line, you don't need an array of pointers to type int. You just need an array of ints.

To get the output you want you can use an index int:

for(int index = 0; index < numberofIntsInArray; ++i)
cout << "Array [" << index + 1 << "] = " << arrayOfInts[index] << endl;

Votes + Comments
Still need ur help

m still not getting the desired output... we have to use array of pointers to type int..

1 – Declare an array of pointer integer type having five elements.
2 – Declare and initialize integer array of five elements named as a. For example:         

     int a = {1,2,3,4,5};

3 – Declare and initialize an array of character type, named as b. For example:

     char b = {‘a’,’b’,’c’,’d’,’e’};

4 – You have to assign values of integer array to integer pointer array.
5 – Then you have to assign values of character array to pointer array of integer type.
6 – Print values of array a, so that the output is as below (for the set of values as provided in step 2 and 3)

This is all what i have to do... now plz help me regarding this...


I've seen some ludicrous assignments in my day, but this one is among the most absurd I've ever encountered. I would be tempted to walk out on the class if I were handed a project as pointless as this. Still, an assignment is an assignment...

The key to this assignment is to see that the professor wants you to have set the pointers in the first array so that they each point to the matching element in the second array. To do this, you'll need to loop through the pointer array and set each pointer separately:

    for (int i = 0; i < 5; i++)            //assign values of integer array
    {                                      //to integer pointer array
        ptr[i] = &a[i];

Now here comes the part I consider silly. You need to loop through the character array, and set the values pointed to by the elements of the int pointer array (that is to say, the elements of the int array) to the values in the char array.

    for (int i = 0; i < 5; i++)            //assign values of char array
    {                                      //to the pointer array's references
        *ptr[i] = b[i];

Finally, you need to loop through the int array a, and print it's values. This part does nothing in regards to pointers; you just print the values in the a array.

Now, I suppose that the point of this (if there is one) is to demonstrate what happens when you print characters out as their ASCII values, or some such nonsense. The whole thing seems to be poorly conceived on the instructor's part.

Edited by Schol-R-LEA

This topic has been dead for over six months. 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.