Question: Correct the errors in C in Visual Studio and GCC as appropriate: #include #pragma warning(disable : 4996) // Note: You may notice some warnings for
Correct the errors in C in Visual Studio and GCC as appropriate:
#include#pragma warning(disable : 4996) // Note: You may notice some warnings for variables when you compile in GCC, that is okay. #define macro_1(x) ((x > 0) ? x : 0) #define macro_2(a, b) (2*a + 3*b + 4*a * b - a*b * 5) int function_1(int a, int b) { return (2*a + 3*b + 4*a * b - a*b * 5); } // Part 1: // It appears that the result of macro_1 should be 5, why is the result 6? Correct the error. (5 points) void part1(int x) { int m = x, result; result = macro_1(++m); printf("macro_1(%d) = %d ", (++x), result); // Why did this error occur? Please provide the answer in your own words below following "Explanation: " printf("Explanation: __________________________________________________________________ "); // (5 points) } // Part 2: // Run this program in Visual Studio and then again in GCC. Take note of the output values for function_1(x,y) and macro_2(x,y). void part2(int x, int y) { int i, j, s, t; s = i = x; // initialize variables with value from x t = j = y; // initialize variables with value from y printf("function_1(x, y) = %d macro_2(x, y) = %d ", function_1(++i, ++j), macro_2(++s, ++t)); // Replace the 4 '__' spaces below with the actual output observed when running the code in VS and GCC. printf("In VS : the result of function_1(x, y) = __ and macro_2(x, y) = __ "); // (5 points) printf("In GCC: the result of function_1(x, y) = __ and macro_2(x, y) = __ "); // (5 points) // Explain why Visual Studio and GCC programming environments could possibly produce a different value for the same program and for the same input. printf("Explanation: __________________________________________________________________ "); // (5 points) } // Do not edit any of the following code int main() { int x = 4, y = 5; printf("Part 1: "); part1(x); printf("Part 2: "); part2(x, y); return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
