An invariant is like a rule or an assumption that can be used to dictate the logic of your program.
For example, suppose you have some software application that keeps track of user accounts. Suppose also that user can have multiple account, but for whatever reason you need to differentiate between a user's main account and "alias" accounts.
This could be a DB record or something else, but for now lets assume each user account is represented by a class object.
class userAccount
{
private char * pUserName;
private char * pParentAccountUserName;
...
}
An invariant might be the assumption that if pParentAccountUserName is NULL or empty then this object is the parent account. You can use this invariant to distinguish different types of account. There are probably better methods to distinguish different types of user accounts, so keep in mind this is just an example to show how an invariant might be used.