data type in function parameters

ive seen code where when someone creates a function the parameters give two data types but no identifiers for the parameters like this:
1
2
3
4
int randomFunction(int, int)
{
...code stuff here
}


so what does this do??
this code does nothing cos it's wrong :)

function can be "described" in two ways:

first is DECLARATION:
int randomFunction (int, int);

second is DEFINITION:
1
2
3
int randomFunction (int x, int y) {
        // some stuff here
}


DECLARATIONS must be "declared" before main () function or in header file (*.h) and then included with #include "headerName" command
where identifers are irrelevant (not inpotant)
what declaration does -> it let the compiler know what type of argument functioin will take and what will reutn

and DEFINITIONS are mostly "defined" after function main () or in seperate *.cpp file
where identifers must! be included otherwise wont work
what definition does -> it tels the compiler exactly what funtion can do

DEFINITION and DECLARATION argument types (int, double ...)must match otherwise compiler return's error and wont compile.

why to use declaration ?
you don't have to... u can use only definition but then definition must be before function main ()
in same file so the compiler will know that function exist and what it will do.

declaration are used because if u have many functions u will like to put them into seperate file and not mesed up wint your main code

1 more option is puting only definiton into header which is VERY BAD practice.
hope you got it :)
Last edited on
thank you! makes far more sense now :)
where identifers must! be included otherwise wont work


I'm afraid that's wrong.

Unnamed parameters are acceptable to be used just like how unnamed enums, classes, etc can be used.

Their purpose is to signify that the variable is unused in the function.
Topic archived. No new replies allowed.