Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Find out the error if any, in the program. #include <stdio.h> int main(){ int

ID: 3540753 • Letter: 1

Question

1. Find out the error if any, in the program.

#include<stdio.h>

int main(){

    int i=1;

    switch(i){

         case 1: printf(" adioactive cats have 18 half-lives");

         break;

         case 1*2+4: printf("ottle for rent -inquire within");

         break;

    }

    return 0;

}

2. Find out the error, if any, in the following program.

#include<stdio.h>

int main(){

    int a=10,b;

    a= 5 ? b=100 : b=200;

    printf(" %d",b);

    return 0;

}

3. In the following code, in which order the functions would be called?

a= f1(23,14)*f2(12/4)+f3();

a) f1, f2, f3

b) f3, f2, f1

c) The order may vary from compiler to compiler

d) None of the above

4. What would be the output of the following program?

#include<stdio.h>

int main(){

    int i=4;

    switch(i){

         default:

             printf(" A mouse is an elephant built by the Japanese");

         case 1:

             printf(" Breeding rabbits is a hair raising experience");

             break;

         case 2:

             printf(" Friction is a drag");

             break;

         case 3:

             printf(" If practice make perfect, then no body's perfect");

    }

    return 0;

}

a) A mouse is an elephant built by the Japanese

b) Breeding rabbits is a hare raising experience

c) All of the above

d) None of the above

5. What is the output of the following program?

#include<stdio.h>

#define SQR(x) (x*x)

int main(){

    int a,b=3;

    a= SQR(b+2);

    printf("%d",a);

    return 0;

}

a) 25

b) 11

c) error

d) garbage value

Explanation / Answer

1. No error. Constant expression like 1*2+4 is acceptable in cases of a switch.

2. Lvalue required in function main(). The second assignment should be written in parenthesis as follows:

a= 5 ? b = 100 : (b=200);

3. c) The order may vary from compiler to compiler

4. c) All of the above

5. b) 11