Professional Documents
Culture Documents
ESC Quiz1
ESC Quiz1
30 && ((e == f) && d) || (@ = 30) || (b = nrinttiMOnd OLA OLA Oss Obs Oka" a he dw Ae Itpsietoticac ivesc101a2122Mresu28 200)) { ana11/22, 600 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 Your answer: 40 2050 1913 Feedback: Incorrect answer QB What is the output of the code snippet? int arr] = {1, 4, 8, 3}; int sum = 0; for (int i = 0;i <4; i++) { sum += arrfi]; } intk = 4) int flag for (int i = 3; i >= 0; i-) { if (sum /k < arrfi]) flag = 0; + printf("%d", flag); Max. score: 3; Neg. score: 0; Your score: 0 Your answer: 2 Feedback: Incort answer Q9 Find how many times the do-while loop gets cuted in the following code snippet aH; peers) htpsshelaitk acinveset01a2122/#resuv28 o35111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 5; Neg. score: 0; Your answer: INFINITE LOOP Feedback: wrong answer Q10 Consider the following cod int a{] = {1,2,3,4,5,6,7,8,9,0} for (int i = 0; i < 10; i++) { if (i < 7 &&i++%3 ali++] = 0; + tow many non-zero elements are there in the array a after executing the snippet? Does the answer change for multiple executions of the for loop on a? Max. score: 6; Neg. score: O; Your score: 0 Your answer: 8 Feedback: Part(a) incorrect Part(b}- not answered Q.11 Consider the following where a, b, ¢ dare integers. What is the value of d? Max. score: 2; Neg, score: 0; Your score: 2 htpsshela tk. acinveset01a2122/#resuv28 ens511122, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 10 Q412 Consider the following code snippet. int trimulti(int n): 1) return 1; else return trimulti(n-1)*trimulti(n-2)*trimulti(n-3); Answer the following questions based an the cade snippet. (a) Ifn=4 is passed to the function, three different respective return value spaces will be allocated in the stack for the three calls to trimulti(). (b) The stack space required to execute trimulti(3) will be more than the space required for trimulti(2). (c) How many times will trimulti() be reauired to be called if trimulti(4) is calculated? Max. score: 6; Neg. score: 0; Your score: 0 Your answer: Feedback: Q13 Rohit wrote a program to evaluate the value of a mathematical expression. #include#include int funcl(char c) { return (¢ >= '0' && ¢ <= '9'); + int func2(char c) { return (c - ‘1'); } int evaluate(char *eqn) { if (*eqn == '\0') return -1; int val = func2(eqn{0)); htpsshelaitk ac nveset01a2122I#resuv28 m35111722, 6:00 PM ESC101/AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 val += func2(opd); else if (opr == '-') val -= func2(opd); else if (opr ) val *= func2(opd); else if (opr == '/') val /= func2(opd); else return -1; + return val; } int main() { char eqn{500]; scanf("%s", eqn); int val = evaluate(eqn); (val == -1) ? printf("%s is Invalid", eqn) : printf("Value of %s is %d", eqn, val); return 0; } However, the code turned out to be wrong. Show the output of the shown code given the inputs given below. Input: 3+7/3+5 Input: 5+4"2/8 Input: 9+6/4°3 Input: 4444 Briefly explain where Rohit went wrong. Note that you do not need to provide the corrected code, just point out the error. The variable “eqn’ is a string, We need pointers when we pass strings into a function, which you will learn later in this course. For now, think of "eqn" and “eqn” as arrays, and that ean|i] gives us the (i+1)-th character, as is usually the case with arrays. ‘Max. score: 10; Neg. score: 0; Your score: O Your answer: Feedback: Q14 Which of the following are valid variable names in C? There can be more than one correct choice. Max. score: 1; Neg, score: 0; Your score: 1 htpsshela tk. acinveset01a2122/#resuv28 ans5111/22, 500 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 var var&1 Q15 Passing a long value to a function defined as int foo{int a) in the caller program will not give a compilation error. Max. score; 1; Neg. score: Q; Your score: 0 true Q.16 Not passing arguments to a function defined as int foo(int a) in the caller program will give a compilation error. Max. score: 1; Neg. score: Q; Your score: 1 false true Q.47 How should the character array a be initialized so that the output of the given code is CSENTK? #include int main(){ char a[8] = " " char b[8} b[7] = \0 for (int i = 6; i >= 0; i-) { b{6-i] = afi] + + printf("%s", b); return 0; } Max. score: 3; Neg. score: 0: Your score: 0 Your answer: Feedback: htpsshela tk. acinveset01a2122/#resuv28 ons5.00 PM 101A: FUNDAMENTAL OF COMPUTING int foo(int A[] ,int n) { int poss[n]; (Cuaeecrren eres) poss[i]=0; heed poss[last]=1 (int i=last-1;i>=0;i--) { Gey Ea peers) { Pert A a (int j=it1;5<=i+ALi];j++) nf (poss[j]) poss[i]=1; Tay int main() 55 int A[é] = {3,2,1,0,4,1}; printf(" d", foo(A,6), foo(A+2,4) ,foo(A+4,2)); 101135111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 leg. score: 0; Your score: 0 bY not add two char Compilation error because you Character not in the English alphabet Another valid character Q.20 Select the correct option about the output of the following snippet, int main() { inti= while(i { if(i == 5) { break; + i+=2; printf("%d",i); + ax. score: 2; Neg. score: 0; Your score: O Compile error Infinite Loop 7 hitpsinelastk.acivese101a2122iMresuv28 na5111722, 6:00 PM ESC101/AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 int main(){ int x func(x return 0; + = 1); ‘Max. score: 1; Neg, score: Q; Your score: 0 false true 2 Give the output of the following snippets, or indicate the error with a brief explanation. 3X(d = 2" jprintf("96d 96d %d 9% %d %, Max. score: 3; Neg, score: Q; Your score: 1 Your answer: Error 223446 242462124 Feedback: Part(b) is incorrect, Explanation not provided for part(a) Score: 9.5 htpsshela tk. acinveset01a2122/#resuv28 ra5111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 htpsshela tk. acinveset01a2122/#resuv28 sa