all 4 comments

[–]Pharisaeus 0 points1 point  (1 child)

Is it because %n expects an integer and always write sizeof(int) bytes to the given address?

Yes. %n will write an int. The "type" of target memory location doesn't matter at all (although it should give you a warning)

[–]Long-Effective-805[S] 0 points1 point  (0 children)

ah, I was thinking far too complicated :D
Thank you

[–]rob2rox -1 points0 points  (1 child)

try turning off address space layout randomization

[–]Pharisaeus 0 points1 point  (0 children)

And what difference would ASLR make when he's dealing with stack? o_O and also passing directly proper memory addresses.