You are on page 1of 4

Assessment Test 2

1) How many times will Hello be printed in the above program?


#include <stdio.h>

int main()
{
int i = 1024;
for (; i; i >>= 1)
printf("Hello");
return 0;
}

How many times will Hello be printed in the above program?


a) 10 b) 11 c) Infinite d) Compile Time Error
2) What is the output of the below program?
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("Hello");
break;
case '1': printf("World");
break;
default: printf("HelloWorld");
}
return 0;
}

a) Hello b) World c) HelloWorld d) Compile Time Error


3) The value of j at the end of the execution of the following C program.
int incr(int i)
{
static int count = 0;
count = count + i;
return (count);
}
main()
{
int i,j;
for (i = 0; i <=4; i++)
j = incr(i);
}

a) 10 b) 4 c) 6 d) 7
4) The default value of an integer global variable is ________
5) Predict the output of the following program, if a, b and c are 5, 7 and 3 respectively
(assume integer range is -32768 to 32767)
void main ()

{
int a,b,c;
printf (\n Enter three numbers);
scan f (%d %d %d, &a, &b, &c);
if ((a-b) & 32768)
{
if ((a-c) & 32768)
printf ( %d, a);
else
printf ( %d, c);
}
else
if ((b-c) & 32768)
printf ( %d, b);
else
printf ( %d, c);
}

a) 5 b) 3 c) 6 d) 7
6) If a=4, b=6 then the values of a and b after the following code executes is
a=a^b;
b=b^a;
a=a^b;

a) a=5,b=7 b) a=4,b=4 c) a=6,b=4 d) a=6,b=6


7) The output of the following C program is __________.
void f1 (int a, int b)
{
int c;
c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
int c;
c=*a; *a=*b;*b=c;
}
int main()
{
int a=4, b=5, c=6;
f1(a, b);
f2(&b, &c);
printf (%d, c-a-b);
return 0;
}

8) If a is a float(assume size of float is 4 bytes) variable and &a=1000, then int *p=&a; p=p+4;
then printf(%d,p) will print the value ______________
9) The output of the following C program is
void fun(int *p)
{
int q = 10;
p = &q;
}

int main()
{
int r = 20;
int *p = &r;
fun(p);
printf("%d", *p);
return 0;
}

a) 10 b) 20 c) Run Time Error d) Compile Time Error


10) Predict the output
#include <stdio.h>

int main()
{
float c = 5.0;
printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);
return 0;
}

a) Temperature in Fahrenheit is 41.00 b) Temperature in Fahrenheit is 37.00


c) Temperature in Fahrenheit is 0.00 d) Compile Time Error

11) Predict the output of the following program


#include <stdio.h>
int fun()
{
static int num = 16;
return num--;
}

int main()
{
for(fun(); fun(); fun())
printf("%d ", fun());
return 0;
}

a) Infinite loop b) 13 10 7 4 1 c) 14 11 8 5 2 d) 15 12 8 5 2
12) Predict the output of the following program
int main()
{
int x=10;
int *ptr = &x;
printf("%d\n", *&*&*ptr);
return 0;
}

a) 10 b) address of x c) address of ptr d) Compile Time Error

13) Predict the output of the following program


#include<stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d \n", i, j);
getchar();
return 0;
}

a) 2 2 b) 2 1 c) 0 1 d) 0 2
14) The value printed by the following program is
void f(int* p, int m)
{
m = m + 5;
*p = *p + m;
return;
}
void main()
{
int i=5, j=10;
f(&i, j);
printf("%d", i+j);
}

a) 10 b) 20 c) 30 d) 40

15) The following code will print ______________


int x = 10;
int y = (x++, ++x);
printf("%d", y);

You might also like