Why it seems that the function I defined can't run [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2020-05-23 11:55:05

问题


When run, I cannot input anything and the program just end and return nothing, though in my code I want to input and output something. And then I tried to debug, I set a lot of key points in the function that I defined, but it directly goes to the end of the code. It seems that the function I defined can't be run. I am confused about that. Could you tell me what was wrong? Thank you in advance.

#include<stdio.h>
void day_of_year();
int main() {

    day_of_year;
    return 0;
}
void day_of_year()

{
    int year; int month; int day;

    scanf_s("%d %d %d", &year, &month, &day);
    int day_tab[2][13] = {

    {0,31,28,31,30,31,30,31,31,30,31,30,31},

    {0,31,29,31,30,31,30,31,31,30,31,30,31} };

    int flag, j;

    flag = (year % 400 == 0) || ((year % 100 != 0) && (year % 4) == 0);

    for (j = 1; j < month; j++)  day += day_tab[flag][j];
    printf("%d", day);
}

回答1:


To call the function, your statement should read day_of_year();, with the parentheses.

Without the parentheses, day_of_year; is an expression that evaluates the address of the function, then doesn't do anything with it.




回答2:


You need to call it by adding a set of parenthesis. Otherwise it's just an unused expression.

int main() {

    day_of_year();
    return 0;
}


来源:https://stackoverflow.com/questions/61788495/why-it-seems-that-the-function-i-defined-cant-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!