arrays - At which memory segment does pointer c+9 point for given function? -


  1. void f() {int *c=(int*)malloc(10);}
  2. void f() {int c[10];}

i think on in first case c+9 pointing @ element c[9] in array allocated on heap.

and second case think c+9 pointing @ same element c[9] of array located on stack.

i new programming , not sure if correct answer. help.

in both cases behaviour undefined. in case 1 points beyond allocated piece of memory. in case 2 points array allocated on stack , has been popped.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -