0
Pointer to acess array .. i wanna acess to 2nd place in the array with ++ operator it doesn't work??
#include <iostream> using namespace std; int main() { int numbers[4]={10,20,30,40}; cout<<numbers[3]<<endl; cout<<*numbers<<endl; numbers ++; cout<<*numbers<<endl; }
8 Answers
+ 2
In that case, msg and ptr both points to the same memory location (beginning of the "hello" string).
However, ptr is a pointer data-type, and msg is an array-datatype, and that makes all the difference : you cannot increment an array, since it has to be a constant value.
On the contrary, a pointer doesn't have to be constant, and you can increment it.
+ 2
Check this:
https://code.sololearn.com/cjGlTF5WW4ir/?ref=app
+ 2
Ah. Nevermind my question
Is there any difference between i++ and i+=1 or i=i+1 in its deeper function?
+ 2
Even if an array is basically a pointer, it does not behave totally like pointers : you cannot perform increment / decrement on it.
However, you can do :
*(number + n)
[Edit]
number[n] // or [n]number
Is syntax sugar for
*(number + n)
0
Why should this work?
i=1
i++
numbers[i]
0
Why increment work in charcter array like this
Char msg[ ]="hello";
Ptr=msg;
Ptr++;
*ptr='a';
It will be hallo
0
Nivid , i am beginner so i think no difference or what?
0
Oh sorry i misunderstand increment done to pointer "ptr"which is firstly assigned to array
Thank you all đ