Pointers for int and Arrays

Viewed 96

Hello i'm a noob in programming, i have a small doubt regarding pointers

#include<iostream>
using namespace std;

int main()
{
    int myAge = 16;
    int* agePtr = &myAge;

    cout << "address of pointer" << agePtr << "Data at memory address" << *agePtr << endl;

    int badNums[5] = {4, 13, 14, 24, 34};
    int* numArrayPtr = badNums;

    cout<< "address" << numArrayPtr << "value" << *numArrayPtr << endl;

    numArrayPtr++;

    cout<< "address" << numArrayPtr << "value" << *numArrayPtr << endl;

    return 0;
}
  • In the first case while pointing an integer i use &myAge where as in the second case of incrementing Arrays if i use &badNums the compiler is returning an error, but if i use badNums its compiling why should we use badNums instead of &badNums in the second case?

  • how can I increment the value in integer using pointers?

3 Answers
Related