Formal charge is the charge that would be assigned to an atom in a molecule in the limit that all atoms had identical electronegativity (or, if you will, all bonds are perfectly covalent). Contrast this to oxidation state of an atom, which assumes all bonds in a molecule are perfectly ionic - the valence electrons are fully surrounding the atom with higher electronegativity, no matter how small the electronegativity difference is.
In carbon dioxide, to determine the formal charge, the C's and the O's are assumed to have the same electronegativity, and the formal charges on all the atoms are equal to zero, as the formal charge formula is V-N-B/2, where V is the # of valence electrons, N is the number of electrons in nonbonding orbitals around the atom, and B is the number of bonding electrons surrounding the atom, divided by 2. (For instance, each oxygen has 6 valence electrons, two pairs of nonbonding electrons, and two bonds with two electrons each, so F = 6-4-4/2 = 0.)
On the other hand, if we adopt the oxidation state limit (completely ionic bonds), then all the bonding electrons are possessed by the atoms with a higher electronegativity (oxygen in this case). So the oxygens have an oxidation state of -2 each and carbon has an oxidation state of +4.
Realize that both formal charges and oxidation states represent idealized situations and in most cases, neither is a truly realistic picture of the where electrons are in a molecule. In most cases, the true degree of electron sharing is somewhere in the middle - they may spend more time than average around the oxygen atoms than the carbon atoms, given that oxygen atoms are more electronegative, so there is a partial negative charge around oxygens and a partial positive charge around the carbon, and the "units of charge" lay somewhere between the formal charge limit and the oxidation state limit. Whether more toward the latter or former depends on the degree of electronegativity difference between the atoms.
Note that in CO2, no matter what charge distribution model one takes (oxidation state, formal charge, or a more realistic picture that would be determined through sophisticated computer modelling), the dipole moment is zero and the molecule is nonpolar, because all the charge asymmetries cancel each other out.