Pointers and Arrays in C/C++

Hey guys Im trying to get down some theoretical stuff for Pointers and Arrays. I was hoping someone could reaffirm some suspicions I had with the concept of pointers and arrays. Suppose I had something like this int ia[] = {0,1,2,3,4,5}; ia[2]; // =2 int* ip = &ia[0]; // pointer ip gets the address of element 0 in array ia ip[2]; // ?? ip[2] = 42; // Most of this code is theoretical obviously but im a bit unsure of the last 2 lines. First off is saying ip[2] the same as saying ip now points to the 2ndth element in the array? Is it equivalent to saying *ip = ia[2] ? Im also confused with the last line. ip[2] = 42; so the 2ndth element of the object that the ip points to, that address gets the value 42? Or is that an array notation method of dereferencing? Im just a bit confused on whats going on.
ip[2]; is a statement that has a value and does nothing with it. It's the same as saying i; 3; or main;. AKA it does nothing.

以上就是Pointers and Arrays in C/C++的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准