Question: Consider the following program (that illustrates a common pitfall): #include #include void tryToSwap(int, int); int main(void) { int num1 = 4; int num2 = 8;

 Consider the following program (that illustrates a common pitfall): #include #include

Consider the following program (that illustrates a common pitfall): #include #include void tryToSwap(int, int); int main(void) { int num1 = 4; int num2 = 8; printf("%d %d ", numi, num2); tryToSwap (numi, num2); printf("%d %d ", numi, num2); return 0; } void tryToSwap(int numi, int num2) { int temp = num; num1 = num2; num2 = temp; } What will be printed to the screen? o 4 8 O 4 8 4 8 4 8 84 O Doesn't compile O Compiles but outputs something else Why does the output look like that? (Select one of the following that is true). num1 and num2 are pass-by-reference, which means their values will be copied into local variables in the function. Changing the value of the local variables inside the tryToSwap function has no effect on the values of variables inside main. o num1 and num2 are already defined in main, which means the code will actually not compile due O to errors. num1 and num2 are pass-by-value, which means their values will be copied into local variables in the function. Changing the value of the local variables inside the tryToSwap function will result in garbage values in the variables inside main. O num1 and num2 are pass-by-value, which means their values will be copied into local variables in the function. Changing the value of the local variables inside the tryToSwap function has no effect on the values of variables inside main O

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!