Functions


Similar to functions in MATLAB, except:

Below is a simple MATLAB function calling a subfunction, and its equivalent C-code

 

MATLAB Function


function main( )
a = 2;
b = 3;
result = timestwo(a, b);
disp(result);

% Begin function "timestwo"
function result = timestwo(a, b)
result = 2*(a+b);

Equivalent C-Code
#include <stdio.h> void main( ) { int a, b; int result; a = 2; b = 3; result = timestwo(a, b); printf ("The result is %d\n", result); } /* Begin function "timestwo" */ int timestwo (int a, int b) { int result; result = 2*(a+b); return (result); }

Note:
"timestwo" is an int function because its output is an integer value

 


Back to the Index