Home » C++ Programming » Pointers » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    int main ()
    {
    int num[5];
    int * ptr;
    ptr = num; *ptr = 12;
    ptr++; *ptr = 21;
    ptr = &num[2]; *ptr = 35;
    ptr = num + 3; *ptr = 14;
    ptr = num; *(ptr + 4) = 53;
    for (int k = 0; k < 5; k++)
    cout << num[k] << ",";
    return 0;
    }
    1. 12,21,35,14,53,
    2. 35,14,53,
    3. 14,53,
    4. 12,21,35,14
    5. 12,21
Correct Option: A

In this program, we are just assigning a value to the array and printing it and immediately dereferencing it.



Your comments will be displayed only after manual approval.