I've noticed in various smart contract tutorials that different versions of Solidity are declared at the top. I would assume that you would just use the latest but I've noticed that certain contracts seem to work on one platform don't work on another i.e. deploying the same contract via Remix & MetaMask vs Mist?
It's a safety feature.
It might help to think of the
solc compiler as a possible source of defects. It's a way of stating the version of compiler that was used in development and testing.
Consider a situation in which a team has conducted painstaking testing at great expense. Then, a series of unfortunate circumstances leads to a compile using a newer compiler. They put it into production with the mistaken belief that it was thoroughly tested, but in reality, it's different and broken. Oops!
The compiler will throw an error if it doesn't match what the source file asks for.
pragma solidity 0.4.11; // version 0.4.11. Nothing else will do. pragma solidity ^0.4.11; // version 0.4.11 or newer
In my opinion, the ^ notation is convenient for informal development. The precise notation is required before extensive testing or release.
It basically says "this code was compiled with 0.4.11" and people can compile the source themselves and see that it matches exactly. Implicitly, if the version that was tested was compiled with something else, then "this" bytecode wasn't really tested at all.
Hope it helps.