Are Pointers and Arrays Interchangeable?

Author Topic: Are Pointers and Arrays Interchangeable?  (Read 350 times)

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 43
  • Karma: 0
  • Gender: Male
  • I am Chinmay
    • Fat Cutter
Are Pointers and Arrays Interchangeable?
« on: 09-27-2016, 06:20:03 »
As the preceding few pages have shown, pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable in many cases. For example, a pointer that points to the beginning of an array can access that array by using either pointer arithmetic or array-style indexing. However, pointers and arrays are not completely interchangeable. For example, consider this fragment:

Code:
Only registered users can see contents. Please click here to Register or Login.]
'
Here, num is an array of integers. As the comments describe, while it is perfectly acceptable to apply the * operator to num (which is a pointer operation), it is illegal to modify num’s value. The reason for this is that num is a constant that points to the beginning of an array. Thus, you cannot increment it. More generally, while an array name without an index does generate a pointer to the beginning of an array, it cannot be changed.


 

Related Topics

  Subject / Started by Replies Last post
1 Replies
584 Views
Last post 12-21-2015, 23:51:03
by RH-Calvin
0 Replies
305 Views
Last post 11-07-2016, 03:05:08
by aarav