In C, are arrays pointers or used as pointers?

前端 未结 6 1030
野趣味
野趣味 2020-11-22 05:23

My understanding was that arrays were simply constant pointers to a sequence of values, and when you declared an array in C, you were declaring a pointer and allocating spac

6条回答
  •  一整个雨季
    2020-11-22 05:37

    If 'y' is a constant pointer, why does it have a size of 20, like the sequence of values it points to?

    Because z is the address of the variable, and will always return 8 for your machine. You need to use the dereference pointer (&) in order to get the contents of a variable.

    EDIT: A good distinction between the two: http://www.cs.cf.ac.uk/Dave/C/node10.html

提交回复
热议问题