How to find the external points of a square/rectangle contour?

welcome.

use a debugger. perhaps use gdb, or use visual studio. look at all the variables in your program, as it runs.