How to treat verbatim as a block that can be referenced just like a figure?

without option float there is a better spacing here.

\documentclass{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[language=C,frame=single,caption=My caption here,label=code1]
int main()
  {
  }
\end{lstlisting}

From code~\ref{code1} it can be seen clearly....

\end{document}

\documentclass{article}
\usepackage{listings}

\begin{document}

\lstset{language=C,frame=single}

\begin{lstlisting}[float,caption=My caption here,label=code1]
int main()
{
}
\end{lstlisting}

From code~\ref{code1} it can be seen clearly....

\end{document}