Question
What will be the output of the following code snippets and briefly explain the logic: (C PROGRAM PLEASE) 5. int main(void) { int a =
What will be the output of the following code snippets and briefly explain the logic: (C PROGRAM PLEASE)
5. int main(void) { int a = 3, b = 4, c; c = b a; switch (c) { case 1 || 2: printf("God give me an opportunity to change things"); break; case a || b: printf("God give me an opportunity to run my show"); break; } return 0; } 6. #include
return 0; } 7. Suppose, x is a variable of type int, y is a variable of type float, and z is a variable of type double. What is the type of the expression x * y / z ? 8. Write statements to accomplish the following: a. Define table to be an integer array and to have 3 rows and 3 columns. Assume the symbolic constant SIZE has been defined to be 3. b. How many elements does the array table contain? Print the total number of elements. c. Use a for repetition statement to initialize each element of table to the sum of its subscripts. Assume the integer variables x and y are defined as control variables. 9. For the following program, state the scope (either function scope, file scope, block scope or function-prototype scope) of each of the following elements. The variable x in main. The variable y in cube. The function cube. The function main. The function prototype for cube. The identifier y in the function prototype for cube. int cube(int y); int main(void) { int x; for (x = 1; x <= 10; ++x) printf("%d ", cube(x)); } int cube(int y) { return y * y * y; } 10. Give the function header(prototypes) for each of the following functions. a. Function hypotenuse that takes two double-precision floating-point arguments, side1 and side2, and returns a double-precision floating-point result. b. Function smallest that takes three integers, x, y, z, and returns an integer. c. Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.] d. Function intToFloat that takes an integer argument, number, and returns a floating- point result. 11. Find the error in each of the following program segments and correct the error. a. #define SIZE 100; b. int b[10] = { 0 }, i; for (i = 0; i <= 10; ++i) { b[i] = 1;
c. #define VALUE = 120; d. int a[2][2] = { { 1, 2 }, { 3, 4 } }; a[1, 1] = 5; 12. Find the error (if any) in the following code and specify how to correct it or predict the output along with brief explanation: a. void product(void) { int a, b, c, result; printf("%s", "Enter three integers: ") scanf("%d%d%d", &a, &b, &c); result = a * b * c; printf("Result is %d", result); return result; } 13. Compare Iteration with Recursion.
14. Answer each of the following. Assume that single-precision floating-point numbers are stored in 4 bytes, and that the starting address of the array is at location 1002500 in memory. Each part of the exercise should use the results of previous parts where appropriate.
a. Define an array of type float called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume the symbolic constant SIZE has been defined as 10.
b. Define a pointer, nPtr, that points to an object of type float.
c. Print the elements of array numbers using array subscript notation. Use a for statement and assume the integer control variable i has been defined. Print each
d. number with 1 position of precision to the right of the decimal point.
e. Give two separate statements that assign the starting address of array numbers to the pointer variable nPtr.
f. Print the elements of array numbers using pointer/offset notation with the pointer nPtr. Print the elements of array numbers using pointer/offset notation with the array name as the pointer.
g. Print the elements of array numbers by subscripting pointer nPtr.
h. Refer to element 4 of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr.
i. Assuming that nPtr points to the beginning of array numbers, what address is referenced by nPtr + 8? What value is stored at that location?
j. Assuming that nPtr points to numbers[5], what address is referenced by nPtr = 4? Whats the value stored at that location? 15. Answer each of the following. Assume that unsigned integers are stored in 2 bytes and that the starting address of the array is at location 1002500 in memory.
a. Define an array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. Assume the symbolic constant SIZE has been defined as 5.
b. Define a pointer vPtr that points to an object of type unsigned int.
c. Print the elements of array values using array subscript notation. Use a for statement and assume integer control variable i has been defined.
d. Give two separate statements that assign the starting address of array values to pointer variable vPtr.
e. Print the elements of array values using pointer/offset notation.
f. Print the elements of array values using pointer/offset notation with the array name as the pointer.
g. Print the elements of array values by subscripting the pointer to the array.
h. Refer to element 5 of array values using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation, and pointer/offset notation. i. What address is referenced by vPtr + 3? What value is stored at that location?
j. Assuming vPtr points to values[4], what address is referenced by vPtr -= 4? What value is stored at that location
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started