我在Visual Studio 2013中编写了以下C程序:
#include <stdio.h>
int main(){
int number;
int fibonacci(int number);
printf("please enter number\n");
scanf_s("%d", &number);
printf(fibonacci(number));
return 0;
}
int fibonacci(number){
if (number == 1 || number == 0){
return number;
}
else{
return fibonacci(number - 1) + fibonacci(number - 2);
}
}
它给了我这个错误:
Project7.exe中0x5867F365(msvcr120d.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000002。
我认为这是关于取消引用空指针。我该如何解决?
答案 0 :(得分:2)
printf(fibonacci(number));
应该是
printf("%d", fibonacci(number));
甚至更好
int result = fibonacci(number);
printf("%d", result);