GCTCSITA-C-Aptitude Test-3 Variables,Operators,Conditional statements and operators,Loops and functions

08/07/2010 01:20

GCTCSITA-PLACEMENTS ACTIVITIES

C-Aptitude - Test- 3

Date: 07/07/10

Deduce the output or mention the errors if so.

1. main(){

int i=10;

i=!i<14;

printf(“i=%d”,i);

}

2. int main(){

printf("%c\n", 3["CSITA"]);

return 0;

}

3. main(){
                        char p[ ]="%d\n";
p[1] = 'c';
printf(p,88);
}

4. main(){
int i = 3;
for (;i++=0;) printf(“%d”,i);
}

5. main(){
static int i;
while(i<=10)
(i>2)?i++:i--;
            printf(“%d”, i);
}
6.
main(){
    int i=10,j=20;
    j = i, j?(i,j)?i:j:j;
    printf("%d %d",i,j);
}
7.
main(){
    int i=5,j=10;
    i=i&=j&&10;
    printf("%d %d",i,j);
}

8. Which of the following cannot be checked in a switch-case statement?

A. Character B. Integer C. Float D. enum

9. int main(){

int i = 1;

switch(i)

{

printf("Hello\n");

case 1:

printf("Hi\n");

break;

case 2:

printf("\nBye\n");

break;

}

return 0;

}

10. int main(){

int i = 5;

while(i-- >= 0)

printf("%d,", i);

i = 5;

printf("\n");

while(i-- >= 0)

printf("%i,", i);

while(i-- >= 0)

printf("%d,", i);

return 0;

}

11. int main(){

unsigned int i = 65535; /* Assume 2 byte integer*/

while(i++ != 0)

printf("%d",++i);

printf("\n");

return 0;

}

12. int main(){

float a = 0.7;

if(0.7 > a)

printf("Hi\n");

else

printf("Hello\n");

return 0;

}

13. int main(){

int a=0, b=1, c=3;

*((a) ? &b : &a) = a ? b : c;

printf("%d, %d, %d\n", a, b, c);

return 0;

}

14. int main()

{

int x=1, y=1;

for(; y; printf("%d %d\n", x, y))

{

y = x++ <= 5;

}

printf("\n");

return 0;

}

15. int main()

{

void fun();

int i = 1;

while(i <= 5)

{

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

if(i>2)

goto here;

}

return 0;

}

void fun()

{

here:

printf("It works");

}

16. main()

{

int a = 10, b;

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

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

}

17. Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A. rem = 3.14 % 2.1; B. rem = modf(3.14, 2.1);

C. rem = fmod(3.14, 2.1); D. Remainder cannot be obtain in floating point division.

18. int main(){

printf("CSITA");

main();

return 0;

}

19. main(){

int i=_l_abc(10);

printf("%d\n",--i);

}

int _l_abc(int i){

return(i++);

}

20. main(){

int i=-1,j=-1,k=0,l=2,m;

m=i++&&j++&&k++||l++;

printf("%d %d %d %d %d",i,j,k,l,m);

}

21. main() {

signed char i=0;

for(;i>=0;i++) ;

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

}

22. main() {

int i=-1;

+i;

printf("i = %d, +i = %d \n",i,+i);

}

23. main(){

static int a[20];

int i = 0;

a[i] = i ;

printf("%d, %d, %d\n", a[0], a[1], i);

}

24. main(){

char ch;

ch = 'A';

printf("The letter is");

printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);

printf("Now the letter is");

printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');

}

25. main(){

printf("%x\n", -2<<2);

}

26. main(){

int i=-3, j=2, k=0, m;

m = ++i || ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

}

27. main(){

int x=55;

printf("%d, %d, %d\n", x<=55, x=40, x>=10);

}

28. Which of the following are unary operators in C?

1. ! 2. sizeof 3. ~ 4. &&

29. Which of the following are the correct usage of conditional operators used in C?

A. a>b ? c=30 : c=40; B. a>b ? c=30; C. max = a>b ? a>c?a:c:b>c?b:c

D. return (a>b)?(a:b)

30. Which of the following is correct about err used in the declaration given below?

typedef enum error { warning, test, exception } err;

A. It is a typedef for enum error. B. It is a variable of type enum error.

C. The statement is erroneous. D. It is a structure.