Answers to questions on calling a function

Consider our example from the notes:
#include <stdio.h>

    void PrintTwo(int Val1, int Val2) {
        /* Print 2 ints on a line */
        printf("%d %d \n",Val1,Val2);
    }
    
    int Larger(int IVal1,int IVal2) {
        /*Return the larger of 2 ints*/
        if (IVal1>IVal2) return IVal1;
        return IVal2;
    }
    
    void main() {
        int X;
        X = -100; 
        PrintTwo(X,Larger(X,200));
    }
Plain text to compile and run.

  1. Would it be legal to write Larger(4,6); as a statement on its own?
    Yes, it is an expression ended by a semi-colon and so can be used as a statement.

  2. Would it be legal to write X = Larger(X,200);
    Yes, it is quite legal to assign the result to a variable also used as a parameter.

  3. What would the output be when running the example? Try compiling and running it to check.
    -100 200

Back to the questions.


Next - Function prototypes.