MATLAB: A question about C source MEX File

codemex

According to C Syntax, the function in the first pictures below should return nothing because of "void", and there are should be four inputs(x,y,z,n), but when testing the mex file in the next picture, the function returns an output and there are only two inputs. Why ? ? ?
>>
>>

Best Answer

You're referring to the example on this documentation page?
You are correct that the C function named arrayProduct called by the mexFunction gateway function defined in arrayProduct.c is defined to accept four inputs and return no outputs.
When you compile the MEX-file source code arrayProduct.c to generate the MEX-file arrayProduct (with a platform-specific extension) and call that MEX-file from MATLAB, the inputs and outputs passing between MATLAB and the MEX-file are passed into and out of the mexFunction gateway function, not directly into and out of the C function arrayProduct.
See the "Read Input Data" and "Prepare Output Data" sections on the documentation page for the code in mexFunction that accepts the input from MATLAB and returns the output to MATLAB.
So the flow of data is:
MATLAB --> arrayProduct MEX-file / mexFunction C function
arrayProduct MEX-file / mexFunction C function --> arrayProduct C function
arrayProduct C function --> mexFunction C function / arrayProduct MEX-file
mexFunction C function / arrayProduct MEX-file --> MATLAB