The following employs moredelim and some boxing to have any (syntax-formatted) part of a listing as hyperlink:
int main(){
@foo@(); // <-- identifier is hyperlink
}
The link target (URL) is specified with the macro \btSetUrl{ theurl }. You could setup it once or redefine it inside the listing using any of listings's escape-to-latex options. In the example, I simply use mathescape, so that $\btSetUrl{https://tex.stackexchange.com}$ inside the listing sets the URL.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings,xcolor,beramono}
\usepackage{tikz}
\usepackage{hyperref}
\makeatletter
\gdef\bt@HR@url{https://tex.stackexchange.com}
\newcommand\btSetUrl[1]{\gdef\bt@HR@url{#1}}
\newenvironment{btHyperref}
{\begingroup\begin{lrbox}{\@tempboxa}}
{\end{lrbox}\bt@HR@box{\@tempboxa}\endgroup}
\newcommand\btHR{%
\begin{btHyperref}\bgroup\aftergroup\bt@HR@endenv%
}
\def\bt@HR@endenv{%
\end{btHyperref}%
\egroup
}
\newcommand{\bt@HR@box}[1]{%
\href{\bt@HR@url}{\usebox{#1}}%
}
\makeatother
\lstdefinestyle{C}{
language={C},basicstyle=\ttfamily,
mathescape,
moredelim=**[is][\btHR]{@}{@},
}
\begin{document}
\begin{lstlisting}[style=C]
int main(){
int x;
$\btSetUrl{http://tex.stackexchange.com/questions/314903/inline-links-in-code-listings}$@MyFunction@( x ); // <-- links to cool question
$\btSetUrl{http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c}$@return 0@; // <-- never forget!
}
\end{lstlisting}
\end{document}

MyFunctiondifferent from the rest of the code. Using the answer below to avoid this problem. – user202729 Oct 31 '22 at 08:50