As I understand it.
The part in brackets is vendor-specific information. The Ubuntu tells you that this is a Ubuntu build of gcc, and the string after it is the package version.
The package version is split into two parts by a hyphen (if there is more than one hyphen the last one is used for the split). The "upstream version" and the "Debian revision" (in some cases there may also be an epoch). The "upstream version", may be the literal version number used upstream or it may contain other indications, for example +dfsg to indicate that non-free files were stripped out of the orig tarball or +git to indicate that what is packaged is actually a git snapshot.
In this case the "upstream version" is "7.5.0" (same as the literal upstream version) and the "Debian revision" is "3ubuntu1~18.04"
Changes in the "Debian revision" identify changes in Debian or it's derivatives that do not change the content of the upstream tarball(s). There are a few basic principles when assigning a version number.
- It should to the extent possible uniquely identify a version of a package. Obviously this can't be 100% guaranteed with multiple people making packages but there is a generally accepted practice that derivatives should include a unique "tag" in version numbers they assign.
- When a release is updated, the version number must increase (according to the comparison rules) so that users actually get the upgrade.
- When a package is in multiple releases of a distro, the version in newer releases must be higher than in older releases so that users who upgrade their systems get the correct version.
- It should be meaningful to users.
The tilde character in version numbers is special, in the version comparision algorithm it compares lower than the empty string, that is "1.2.3-2~foo" < "1.2.3-2" < "1.2.3-2foo" it is commonly used when backporting a package to an earlier release, it is also used to represent prerelease versions.
So now lets break the "Debian revision" of this package down.
- "3" is the revision from Debian itself, indicating that the Debian package this Ubuntu package was based on was the third revision they made to their packaging for 7.5.0.
- "ubuntu1" indicates that this package was modified by Ubuntu.
- ~ generally indicates this is a backport of some sort.
- 18.04 appears to indicate what release this package was backported to. This appears from what I can tell to be ad-hoc usage. There are standards for how backports uploaded to the backports repository should be versioned, but this backport was released as a stable update not through the backports repository. The stable update process does not seem to mandate a particular versioning scheme, it suggests using the one from the security updates process, but that doesn't seem to cover the case of a backported package.