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

This code for example:

\begin{verbatim}
int main()
{
}
\end{verbatim}


How to add a label below it to be referenced?

int main()
{
}
[code 1]

-
look for package listings. It can do it for you – Herbert Sep 26 '12 at 9:02
Thanks! It works. – chyx Sep 26 '12 at 9:06

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}

-
Why community wiki? – ℝaphink Sep 26 '12 at 14:06
@Raphink The OP already solved his problem using Herbert's comment. I just wanted to reduce the unanswered by 1. ;) – Harish Kumar Sep 26 '12 at 14:08