r

Recommended Answers

All 3 Replies

Outside of changing array[index] to *(array + index) everywhere I'm not sure I understand what you need to do...

I think he needs to know how to dynamically allocate the array...

char *buffer = NULL;//<-- good style dictates initializing to nullptr.
buffer = new char[1024];//<-- array of 1024 characters.
//use array with familiar notation
delete [] buffer;//<-- delete the allocated memory so you don't "leak" it.
buffer = nullptr;//<-- good style.  delete doesn't do this for you.

Nevermind.

You are on the right track, below is sample of array using index and pointer.

#include <iostream>

int main( int argc, char *argv[])
{
    const size_t LIMIT = 8;
    int buffer[LIMIT] ={0};

    // array access using index notationn
    for(size_t i=0; i < LIMIT; i++)
    {
        buffer[i] = i;
    }
    
    // array access using pointer notation
    for(size_t j=0; j < LIMIT; j++)
    {
        std::cout << *(buffer+j) << std::endl;
    }

    return 0;
}
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.