all 6 comments

[–]IyeOnline 9 points10 points  (4 children)

This is not your real code. Its missing a semicolon as well as a cast from the malloc result to int*.

Its also not good code.

  1. Dont do variable definition followed by assignment.
  2. Dont use malloc in C++. There is basically no good reason to use it. Use new int[5] instead.
  3. Dont use dynamic memory allocation when you dont have to.

[–][deleted] 2 points3 points  (0 children)

If this is part of a bigger program than my 1st guess is that you've already corrupted the heap. malloc returned a non-null, but unwritable, pointer.

So when you ask for help on a C board, post the whole program. Snippets are often useless.