C programlamada yeniyim. Cs50 açık ders yazılımındaki bazı sorun kümelerini yaparak öğreneceğime karar verdim. Aşağıdaki kod Segmentasyon hatası (çekirdek dökümü) hatası üretir. Anlayamıyorum. Bir segmentasyon hatasının, erişemediğiniz belleğe erişmekle ilgili olduğunu okudum. Ama neden, ne olacağını görmüyorum. Bunun işaretçiler ile ilgisi olduğunu varsayıyorum. İşaretçiler konusunda yeniyim. Teşekkür ederim.
#include <stdio.h>
// https://cs50.harvard.edu/x/2021/labs/1/population/
float yearly_llamas(float starting_population) {
// returns number of llamas at the end of the year
float born = starting_population / 3;
float died = starting_population / 4;
float end_of_year_pop = starting_population + born - died;
return end_of_year_pop;
}
int main(void) {
// use floats for precision
float *start_population;
float *end_population;
// set start lower limit
int start_min = 9;
// make sure input for starting population is greater than or equal to 9
do {
printf("Starting population: ");
scanf("%f", start_population);
} while (*start_population < start_min);
// get ending population, make sure greater than or equal to the starting population
do {
printf("Ending population: ");
scanf("%f", end_population);
} while (*end_population < *start_population);
// print for verification
printf("%f\n", *start_population);
printf("%f\n", *end_population);
float end_pop = yearly_llamas(*start_population);
printf("Llamas at the end of the year: %f\n", end_pop);
return 0;
}