Can I set the parameter type and share int foo(someVar){}?

Asked 2 years ago, Updated 2 years ago, 85 views

int foo(someVar){
    return someVar;
}

int main(int argc, const char * argv[]) {
    printf("%d\n", foo(3));
}

SomeVar, the factor of foo(), doesn't have a type There are no compilation errors and the program runs well.

Why is this possible?

c syntax main

2022-09-22 22:19

1 Answers

Writing like that is called an old-style function definition. At this time, parameters that are not specified are automatically declared as int type int foo(someVar) is the same as int foo(int someVar).

Therefore, foo() must return the int type, but someVar of return someVar does not display an error because it is an int type, There is no problem outputting "%d" in the main function.


2022-09-22 22:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.