Application to run on ports

I do not have much idea about ports.

How can i make an application(written in C) to run on a specific port ?

Does the code internally written in C says about port number where the application to run ? Can i make an application to select port dynamically which are closed(other than standard ports for telnet, ftp ...) ?

Does some how port numbers are related to hardware ?

Thanks in advance !

check /etc/services file which will give detailed information about ports used by which application.

Oh, Beej's guide gives you answers to most (if not all) of your questions.

Beej's Guide to Network Programming

Thanks ! It was useful and interesting guide to read.

I did not get answer to my last question out of it ?