Gene alterations (mutations) are central to the cancer process. Mutations can be inherited but in most cases they occur during a person's lifetime. Cancer genes (oncogenes) cause normal cells to grow out of control and become cancer cells. This is a multistep process, with accumulation of mutations in key genes ( and inactivation of tumour suppressor genes).
Such mutations obviously take time, and they work in combination with lifestyle factors and choices (such as diet and smoking). There is also an element of luck it has to be said ! That's why most cancers occur in older people, and also occasionally lifelong cigarette smokers survive to 100 !