本文由我司收集整编,推荐下载,如有疑问,请与我司联系printf在调用通过引用传递变量的函数时发出警告printf在调用通过引用传递变量的函数时发出警告[英]printf gives a warning when calling a function that is passing a variable by reference So I have two functions, one function is passing by reference a variable and the other one is returning the result.
 因此我有两个函数,一个函数通过引用传递一个变量,另一个函数返回结果。
 void dailyMiles(int *totalMiles) int milesDriven, totalDays, totalPeople; peopleInVehicle( totalPeople); //calling other function daysPerWeek( totalDays); // calling other function printf(“Enter the amount of miles driven per day: \n”); scanf(“%d”, milesDriven); I’m having a hard time trying to figure out why it gives me this warning in the terminal:
 我很难弄清楚为什么它会在终端给我这个警告:
  main.c:38:36: warning: format specifies type ‘int’ but the argument has type ‘int *’ [-Wformat] printf(“Total miles saved: %d\n”, totalMiles); ~~ -~~~~~~~~ You are probably wondering why the dailyMiles function’s datatype is void; well, I’m calling other functions that ask for users input so whenever I call it in my main, it asks for users input two times.
 您可能想知道为什么dailyMiles函数的数据类型为void;好吧,我正在调用其他要求用户输入的函数,因此无论何时我在main中调用它,它都要求用户输入两次。
  2
关于printf函数正确的是 You don’t want to print the pointer itself (totalMiles), you want to print what it points to (*totalMiles).
 您不想打印指针本身(totalMiles),您想要打印它指向的内容(* totalMiles)。
  printf(“Total miles saved: %d\n”, *totalMiles); 2
 In function void dailyMiles(int *totalMiles) at statement 10: printf(“Total miles saved: %d\n”, **totalMiles**);
 在函数void dailyMiles(int * totalMiles)at语句10:printf(“保存的总里程数:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。