Use a for statement to print the elements of array values using pointer/offset notation with the array name as the pointer - 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 with the array name as the pointer

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 w w  . jav  a2  s.  c  om

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

Result


Related Tutorials