Use a for statement to print the elements of array 'values' using pointer/offset notation - C++ Data Type

C++ examples for Data Type:Array Pointer

Description

Use a for statement to print the elements of array 'values' using pointer/offset notation

Demo Code

#include <iomanip>
#include <iostream>

int main(int argc, const char *argv[]) {
    const int SIZE = 5;
    unsigned int values[SIZE] = {2, 4, 6, 8, 10};
    unsigned int *vPtr;
    vPtr = values;/* w  ww .  ja  v a2 s .c o  m*/

    for (int i = 0; i < SIZE; ++i) {
        std::cout << std::setw(4) << *(vPtr + i);
    }

}

Result


Related Tutorials