My goal is to successfully link a folder to /opt/ directory- which needs to be run with sudo.
I have tried this:
system(sudo ln -s $$OUT_PWD/xampp /
I think you should use gksudo (in GNOME) or kdesudo (in KDE). The commands will then use a window to prompt for your password.
gksudo
kdesudo