Can someone explain me why is this C program compiling without errors?

AayushGupta69

Hey i am a student learning C programming and just wanted to know that why this program compiles as on line struct date *newdate, foo(); foo is declared as a function local to main function with the return type struct date. As foo is already declared as a function it should give an error of conflicting types as c does not support function overloading. Can somebody please help me.

#include <stdio.h>
#include <stdlib.h>

struct date {
    int month;
    int day;
    int year;
};

struct date foo(struct date x) {
    ++x.day;

    return x;
};

int main() {
    struct date today = {10, 11, 2014};
    int array[5] = {1, 2, 3, 4, 5};
    struct date *newdate, foo();
    char *string = "test string";
    int i = 3;

    newdate = (struct date *)malloc(sizeof(struct date));
    newdate->month = 11;
    newdate->day = 15;
    newdate->year = 2014;
    today = foo(today);

    free(newdate);

    return 0;
} 
dbush

foo is declared as a function local to main function

Not true. It declares but does not define that a function foo exists, and that it takes an unknown number of arguments and returns a struct date.

This declaration is compatible with the actual definition of foo, as the return types match and the declaration makes no statement about the arguments.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can someone explain me how to code this program?

Can someone explain me why is that the output, C++ recursive function

Can someone explain to me why this output is given?

Can someone explain to me why this is possible?

Can someone explain the output of this c++ program?

Can someone please explain the output of this C program?

Can someone explain the output of this program written in C

Can someone explain this C++ code to me which is part of LinkedList program?

can someone explain this equation to me from the c program about generating prime number till 100

Can Someone explain me how this NASM Program works?

Can someone explain me why the following algorithm for LIS is not O(n)?

can someone explain to me why the value of split is false in the test set?

Can someone please explain to me why sorting function returns "None"

Can someone explain to me why the padding of m_data is not initialized?

Can someone explain me why we used curly braces "{}" in this code?

Can someone explain to me why 0.15 - 0.10 = 0.049?;

Can someone explain to me why doesn't this piece of code work?

Can someone help me explain why size value being carried?

Can someone explain this recursive for me?

Can Someone Explain Threads to Me?

Can someone explain this behaviour to me?

Can someone explain me this behaviour?

can someone please explain this to me?

Can someone explain this SQL for me?

Can someone explain this for/in loop to me?

Can someone explain how this code is compiling

Can someone explain this c++ program using vector and algorithm?

Can someone explain the solution of these two questions (c program,mutex,threads)?

Can someone help me to explain what is wrong in my c code?