inherited mostly.
the correlation coefficient is not 1 though, education, upbringing, diet, utilizing and training your brain will increase it.
There have been studies on identical twins reared apart where one twin's iq was 1 to 2 standard deviations higher than the other