Sunteți pe pagina 1din 6

Assessment Test

1) What is the output of the following program?


#include <stdio.h>
#if X == 3
#define Y 3
#else
#define Y 5
#endif

int main()
{
printf("%d", Y);
return 0;
}
a) 3 b) 5 c) 3 or 5 depending on the value of x d) Compile Time Error

2) Predict the output


char *getString()
{
char str[] = "Will I be printed?";
return str;
}
int main()
{
printf("%s", getString());
getchar();
}

Output :

3) Predict the output


int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}

Output :

4) Predict the output


int main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}

Output :
5) Predict the output
# include <stdio.h>
int main()
{
int i=0;
for(i=0; i<20; i++)
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
printf("%d ", i);
}

getchar();
return 0;
}

Output :

6) Predict the output of the following two programs


a)#include <stdio.h>

int main()
{
int i;
i = 1, 2, 3;
printf("i = %d\n", i);
getchar();
return 0;
}

Output :
b)#include <stdio.h>

int main()
{
int i;
i = (1, 2, 3);
printf("i = %d\n", i);
getchar();
return 0;
}

Output :
7) Explain functionality of following function.

int func(int i)
{
if(i%2) return (i++);
else return func(func(i-1));
}
_____________________________________________________________________________________

_____________________________________________________________________________________

8) Predict the output


#include <stdio.h>
int main()
{
int a = 10, b = 20, c = 30;
if (c > b > a)
{
printf("TRUE");
}
else
{
printf("FALSE");
}
getchar();
return 0;
}

Output :

9) Predict the output


int main()
{
int x = 10;
static int y = x;

if(x == y)
printf("Equal");
else if(x > y)
printf("Greater");
else
printf("Less");

getchar();
return 0;
}

Output :

10) Predict the output


#include<stdio.h>
int main()
{
int a, b = 10;
a = -b--;
printf("a = %d, b = %d", a, b);
return 0;
}

Output :

11) Predict the output


int main(void)

{
struct str
{
int i: 1;
int j: 2;
int k: 3;
int l: 4;
};

struct str s;

s.i = 1;
s.j = 2;
s.k = 5;
s.l = 10;

printf(" i: %d \n j: %d \n k: %d \n l: %d \n", s.i, s.j, s.k, s.l);

getchar();
return 0;
}

Output :

12) Predict the output


int main(void)

{
struct str
{
unsigned int i: 1;
unsigned int j: 2;
unsigned int k: 3;
unsigned int l: 4;
};
struct str s;

s.i = 1;
s.j = 2;
s.k = 5;
s.l = 10;

printf(" i: %d \n j: %d \n k: %d \n l: %d \n", s.i, s.j, s.k, s.l);


getchar();
return 0;
}

Output :

13) Predict the output


#include<stdio.h> //assume 16 bits for integer

int main()
{
unsigned int x = -1;
int y = ~0;
if(x == y)
printf("same");
else
printf("not same");
printf("\n x is %u, y is %u", x, y);
getchar();
return 0;
}

Output :

14) Predict the output


void fun(int **p)

{
static int q = 10;
*p = &q;
}

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

Output :

15) Predict the output


#include<stdio.h>
int fun(int n, int *fg)
{
int t, f;
if(n <= 1)
{
*fg = 1;
return 1;
}
t = fun(n-1, fg);
f = t + *fg;
*fg = t;
return f;
}
int main( )
{
int x = 15;
printf ( "%d\n", fun (5, &x));
getchar();
return 0;
}

Output :

16) Predict the output


#include <stdio.h>

int main()
{
int c = 5, no = 1000;
do {
no /= c;
} while(c--);

printf ("%d\n", no);


return 0;
}

Output :

17) Predict the output


#include <stdio.h>

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))


int array[] = {1, 2, 3, 4, 5, 6, 7};

int main()
{
int i;

for(i = -1; i <= (TOTAL_ELEMENTS-2); i++)


printf("%d\n", array[i+1]);

getchar();
return 0;
}

Output :

S-ar putea să vă placă și