Very well done Leeor! I'm impressed you caught some of that stuff. Did you do the clever thing and have a compiler help you out at all?
(That's what I always used to do).
As for the terrible code, it's from a list of
C++ Interview Questions. Spoiler alert, it contains answers in that link.
A couple of additional points:
The
argv[0] element is the program name, rather than the first argument. There is almost no reason to try and interpret it as an integer. Based on the check, and the implied integer conversion intent, it should probably be
argv[1].
If the allocation for the
vector throws, the memory allocated with
new will be leaked.