Nobody mentioning the bug in printf (and how it probably shouldn't be used in the first place)?
%ld = long, but the variable is int. This will work great, until you build that code as a 64bit build on Unix, where a long is 64bit and int is 32bit. Most compilers should even warn about this.
Either use %d or (safer) use cout instead of printf.