C语言中函数名和struct名可以重名!

      在C语言中,函数名竟然可以和struct类型名相同。看下面的程序。定义了struct foo; 和 void foo(struct foo *)两个函数。

#include <stdio.h>

struct foo {
    int a;
    int b;
};

void foo(struct foo *f)
{
    printf("%d, %d", f->a, f->b);
}

int main()
{
    struct foo f;
    f.a = 1;
    f.b = 2;
    foo(&f);

    return 0;
}

可以有正确结果。

原文地址:https://www.cnblogs.com/wangshuo/p/2047714.html