c aptitude question with answer volume 2
28. #define max(a,b) (a>b?b:a)
#define squre(x) x*x
int i = 2, j = 3, k = 1;
printf ("%d %d", max(i,j), squre(k));
output?
a.32
b.23
c.31
d.13
Answer:
DATATYPES
29. void main()
{
int d=5;
printf("%f",d);
}
Answer: Undefined
30. void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1. 1000000
2. Overflow
3. Error
4. None
Answer: 4
31. main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
Answer: 321
32. what is the o/p
printf(" Hello \o is the world ");
Answer: Hello is the world.
33. enum day = { jan = 1 ,feb=4, april, may}
what is the value of may?
a)4
b)5
c)6
d)11
e)none of the above
Answer:
34. main()
{
int x,j,k;
j=k=6;x=2;
x=j*k;
printf("%d", x);
}
Answer: x=1
35. #include<stdio.h>
main()
{
int a,b,c,d=1;
a=10;
b=11;
c=12;
printf("%d %d %d %d %d ");
getchar();
}
a. 10 11 12 1 1
b. 10 11 12 1 Garbage value
c. 1 12 11 10 0
d. Invalid use of arguments at printf
Answer:
36. #include<stdio.h>
#include<conio.h>
main()
{
printf("%c",'\111');
}
a. K
b. A
c. 111
d. a
Answer:
37. Study the following program
#include<stdio.h>
enum mode = {green,red,orange,blue ,white};
main ()
{
green = green +!;
printf("%d,%d",green,red );
}
The output of the program will be :-
A) 1,1
B) 0,1
C) No output, error in compilation
D) None of the above
Answer:
38. Study the following statements.
#define DELAYTIME 1000
volatile extern int k;
intj;
for (i=0;i<DELAYTIME;i++);
j=k;
A) Volatile is meaningless for the variable k
B) Volatile is meaningful for the variable k since k is external and can change
C) Volatile is meaningless for the variable k since k is loop invariant
D) None of the above.
Answer:
39. #include<stdio.h>
main()
{
float value=10.00;
printf("%g %0.2g %0.4g %f",value,value,value,value)
}
Answer: 10,10,10,10.000000
40. #include<stdio.h>
static int i=5;
void main(void)
{
int sum=0;
do
{
sum+=(1/i);
}while(0<i--);
}
41. extern int s;
int t;
static int u;
main ()
{
}
which of s, t and u are availeble to a function present in another file
a. only s
b. s & t
c. s, t, u
d. none
Answer:
42. enum number { a=-1, b= 4,c,d,e}
what is the value of e ?
a) 7
b)4
c)5
d)15
e)3
Answer: a
43. main()
{
enm tag = { left = 10, right, front = 100, back };
printf("%d %d %d %d", left, right, front, back);
}
(a). compile time error
(b). 10 11 100 101
(c). 10 11 12 13
(d). 1 2 3 4
Answer:
44. What is the value of i if you pass value of i to the following function?
foo(const int &j) {
j++;
}
(a). Compile error
(b). 10
(c). prints addition of i
(d). 11
Answer:
SWITCH :
45. void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}
Answer: 1,2,3,4
46. {
ch='A';
while(ch<='F')
{
switch(ch)
{
case'A':case'B':case'C':case'D':ch++;continue;
case'E':case'F':ch++;
}
Answer:
47. what is the error in the following sequence of program.
int i1;
switch(i1)
{
printf("The value of I1 is :");
case 1: printf("%d",i1);
break;
case 2: printf("%d",i1);
break;
default : printf("Invalid entry");
}
Answer:
48. What is an error in the following sequence of a program.
int i;
switch(i)
{
case 1: printf("This is first choice");
break;
case j: printf("This is second choice");
break;
case 1+2+4: printf("This is the third and last choice");
break;
}
Answer:
49. what is an error in the following sequence of a program.
int i;
switch(i)
{
default: printf("This is default value");
break;
case 1: printf("This is first choice");
break;
case 2: printf("This is the second choice");
}
Answer:
50. What is the output of the following program
#include<stdio.h>
main()
{
int i = 0;
switch(i)
{
case 0 : i++;
case 1 : i++2;
case2 : ++i;
}
printf("%d",i++);
}
output of the program :-
A) 1 B) 3 C) 4 D) 5
Answer:
52. #include<stdio.h>
void main(void)
{
unsigned int c;
unsigned x=0x3;
scanf("%u",&c);
switch(c&x)
{
case 3: printf("Hello!\t");
case 2: printf("Welcome\t");
case 1: printf("To All\t");
default:printf("\n");
}
}
Answer:
CONDITIONAL & LOOPING STATEMENTS
53. void main()
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
}
Answer: less
54. int sum(n)
int n;
if(n<1)return n;
else return(n+sum(n-1))
a) 10
b) 16
c) 14
d) 15
Answer:
55. a=10;b=5; c=3;d=3; ///deshaw1.txt
if((a<b)&&(c=d++))
printf("%d %d %d %d",a,b,c,d);
else
printf("%d %d %d %d", a,b,c,d);
Answer:
56. int i =10
main()
{
int i =20,n;
for(n=0;n<=i;)
{
int i=10
i++;
}
printf("%d", i);
}
Answer: i=20
57. main()
{
int ret;
ret=fork();ret=fork();ret=fork();ret=fork();
if(!ret)
printf("sun");
else
printf("solaris");
}
how many sun 4 solaris will get printed?
Answer:
58. For the following code how many times the printf function is executed
main()
{
int i,j ;
for(i=0;i<=10;i++);
for(j=0;j<=10;j++);
printf("i=%d,j=%d\n",i,j);
}
a)121 b) 11 c) 10 d) None of the above
Answer:
59. main()
{
int count = 11;
while (--count+1)
printf("count down is %d \n",count);
}
how many times the printf statement is executed?
Answer: 11.
60. int i;
i=2;
i++;
if(i=4)
{
printf(i=4);
}
else
{
printf(i=3);
}
output of the program ?
a)4
b)3
c)unpredictable
d)none
Answer:
61. output?
initially n = -24;
printd (int n)
{
if (n < 0)
{
printf ("-");
n = -n;
}
if (n % 10)
printf ("%d", n);
else
printf ("%d", n/10);
printf ("%d", n);
}
a. -24 b.24 c.-2424
Answer:
62. main()
{
char s[] = "Never ever look it" , *ch, c = 'e' ;
int i, j;
chr = strcmp ( s, c);
i = chr - s;
for ( i = 0; i < j; i++ )
printf("%d", s[i] );
}
What is the o/p of the program ?
(a). Never eve
(b). Never ev
(c). error
(d). None of the above
Answer:
63. main()
{
int i, j, k = 0;
char c1 = 'a', c2 = 'b';
if ( k == 0 )
printf("K is zero");
else
-----
-----
if ( c1 != 'a' )
printf("c2 == b");
else if ( c2 == 'a' )
printf("c1 == a");
else
printf("Hello");
}
(a). K is zero c1 == a
(b). K is zero c2 == b
(c). K is zero Hello
(d). error
Answer: c
FUNCTIONS
64. int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}
What are the number of syntax errors in the above?
Answer: None.
65. char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}
Answer: anything is good.
66. what is o/p
#include<stdarg.h>
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{
int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{
display("hello",4,12,13,14,44);
}
a) 13 b) 12 c) 44 d) 14
67. int a = 'a', d = 'd';
char b = "b", c = "cr";
main ()
{
mixup (a, b, &c);
}
mixup (int p1, char *p2, char **p3)
{
int *temp;
. ...doesnt matter.....
}
Comment :
(I) what is the value of a after mixup?
a. a b.b c.c d.none of the above
Answer:
(II) what is the value of b after mixup?
a. a b.b c.c d.none of the above
Answer:
0 comments:
Post a Comment