Either by invoking gcc with --help or reading the manual and learning that -dumpversion will output the version, as will --version.
Alternatively, you can use -v which will output gcc's version and build info, and will keep compiling (the others will stop after dumping information).