Client can have any random port selected automatically by OS. So I just need to query with OS for getting port number for client?
Yes. But you don't really have to query OS for this. Call system a function like connect() and the OS will take care of the low level port number details for you. Note that the client does not need to know what port it is running on. Server knows the client port number once the TCP connection is made.
Server port number has to be hard coded in server and client application?
Yes, that is one way to do it.
Server port number should always be 80. Why? And cannot there be some other port number?
It does not have to be 80. It can be anything as long as the port number is known to client. What you are talking about is standard port number for HTTP servers. This does not apply to your private application.
What happens if the port number used by server is already being used some other application on the server?
Once you have designed the system you need to make sure the port number you chose for server is free on the server host. This is easy to do. Choose a server port in the range 49152 – 65535. These are non registered ports that can be used for private use. Just make sure you are not running another private application on the same port on server host.