Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

19
  • 1
    You have undefined behavior when your pointer is going out of bounds of the variable a. Commented Jan 28, 2024 at 15:37
  • You're modifying memory you never allocated. how can I get it to work? By actually using memory you own. Commented Jan 28, 2024 at 15:37
  • 1
    You’re both trying to smash your stack and printing pointers with the wrong format specifier? Commented Jan 28, 2024 at 15:38
  • 1
    Also note that the correct format to print a void * pointer is %p, and a cast is needed. Mismatching format specifier and argument type also leads to undefined behavior. Commented Jan 28, 2024 at 15:38
  • I have been tasked with using a local array declaration that saves all data on the stack of unknown size. As far as I have understood (this very well might be wrong) using malloc the data will be stored on the heap, and the same with a normal array declaration, but that wouldn't really work since the array is of an unknown size. How would I do this then? @tkausl Commented Jan 28, 2024 at 15:48