"p" doesn't point to memory.
You should allocate it yourself, or use a std::vector.
Also, you're using both scanf and cout.
You should either stick to scanf and printf, or cout and cin.
You may also want to add a terminator between those two %d (like: "%d %d") or input them as a string and validate/split them yourself.