You are on page 1of 25

C-APTITUDE.

====================================================================================

INSTRUCTIONS:
a. READ CAREFULLY BEFORE ANS.
b. TRY TO UNDERSTAND THE LOGIC.

1.

main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}

a)i=-1, i=-1
b)i = -1,-i = 1
c)-i=1 ,i=-1
d)i=1,-i=1
Ans. [b]
2. main()
{
printf("%x",-1<<4);
}
a) ffff
b) fff
c) fff0
d) 0fff
Ans: [c]

[c]

3. How do u rectify the error in the following program?


F(struct emp);
Struct emp
4. {

C-APTITUDE.
====================================================================================

char name[20];
int age;
};
main()
{
Struct emp e={raman,35};
F(e);
}
F(struct emp ee)
{
Printf(\n%s %d ,ee.name ,ee.age);
}
a) Structure emp is unkown.
b) There is no prototype.
c) wrong initialization of structure emp.
d)fun prototype to be below structure declaration.
Ans: [d]
5. What would be the output of the following program?
main()
{
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
a)No output
b) c aptitude
c)error
d)none
Ans: [a].
6. what would be the output of the following program?
Main()
{
int i=-3,j=2 k=0,m;
M=++j&&++i||++k;
Printf(n %d%d%d%d,m,k,,j,i);
}
[a ]
a)-2 3 0 1
b)-2 2 0 1
c)-2 3 1 1
d)-2 2 1 1
Ans. [a]

C-APTITUDE.
====================================================================================

7. What is output of the following snipt?


main()
{
printf("%p",main);
}
a)error
b)main
c)Prints some address
d)runtime error
Ans : [C].

[ c]

8. What would be output of the following program?


main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
[b]
a). 5,5.0
b)Compiler error
c)5.0 5.0
d)runtime error
Ans: [b]
9.

C program is a collection of

a)classes
b)objects
c)functions
d)methods

C-APTITUDE.
====================================================================================

Ans: [c]
10. What is output of the following program?
main()
{
char *p;
p="%d\n";
p++;
++p;
printf(p-2,300);
}
a. Error
b. cant increment p
c. 2
d. 300
Ans: [d]
11. What is output of the following program?
main(){
Extern int I;
i=20;
Printf(%d,sizeof (i));
}
a)error
b)20
c)4
d)2
Ans: [a]
12. What is output of the following program?
main()
{
int a[5]={2,3}
printf(\n %d%d%d,a[2],a[3],a[4]);
}
a) Garbage values
b)2 3 3
c) 3 3 2
d)0 0 0

C-APTITUDE.
====================================================================================

Ans: [d]
13. Can we use a switch statement to switch on strings?
a) yes
b) no
c) wrong question
d)none
Ans: [b]
14. Point out the error ,if any in the following program.
Main()
{
Int(*p)()=fun;
(*p)();
}
Fun()
{
Printf(\n am I fun pointer);
}
a)at int(*p)()=fun;
b)at (*p)();
c) at Fun()
d)no error
Ans: [a]

[b]

C-APTITUDE.
====================================================================================

15. Which of the following is the syntax of pointer to an array? [ c ]


a)int *p[10]
b)int [10] *p
c)int (*p)[10]
d)none
Ans: [c]
16.

main()

{
printf("\nab");
printf("\bsi");
printf("\rha");
}
a)hai
b)bia
c)ahi
d)asi
Ans : [a]
17.
What is output of the following snipt?
void main()
{
static int i=5;
if(--i)
{
main();
printf("%d ",i);
}
}
a)5 4 3 2
b)0 0 0 0
c)1 2 3 4
d) 1 1 1 1
Ans : [b]
18.
#define prod(a,b) a*b
Void main()
{

[a]

C-APTITUDE.
====================================================================================

int x=3,y=4;
printf("%d",prod(x+2,y-1));
}
Ans:
a)15

[ d]
b) 19

c) 11

Ans: [d]
19.
{

main()
unsigned char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}
a) infinite loop
b) b)stack overflow
c) c)error
d) d)0
Ans: [a]

20.

21.

#ifdef something
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
a) Compiler Error
b) Runtime Error
c) No Error
d) None of above.
Ans: [a]
What is the output for the following program
main()
{
int arr2D[3][3];

d)10

C-APTITUDE.
====================================================================================

printf("%d\n", ((arr2D==* arr2D)&&(* arr2D ==


arr2D[0]))
);
}
a) 3
b) 2
c) 1
d) None of above
Ans[1]
22.
What is the output for the following program.
main()
{
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}
a) C
b) A
c) c
d) a
Ans : [A]

23.
Main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}

24.

25.

Ans:
45545
fseek(fptr,0,0) is equivalent to
a) ftell
b) rewind
c)a & b
d) none of the above
Ans: a
What is output of following snipt?
void main()
{

C-APTITUDE.
====================================================================================

int *mptr, *cptr;


mptr = (int*)malloc(sizeof(int));
printf(%d,*mptr);
int *cptr = (int*)calloc(sizeof(int),1);
printf(%d,*cptr);
}
Ans:
garbage-value 0
26.

.
27.

What is output of following snipt?


main(){
int i=10,j=20;
j = i, j?(i,j)?i:j:j;
printf("%d %d",i,j);
}
Ans:
10 10
C does no automatic array bound checking. This is
a) true
b) false
c) Cs asset
d) Cs shortcoming
Ans : [a]

28.
void main() {
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);

C-APTITUDE.
====================================================================================

}
Ans:
Here value is 7
29.

main()
{
register int a=2;
printf("Address of a = %d",&a);
printf("Value of a = %d",a);
}

Ans:
Compier Error: '&' on register variable
30. Consider the declaration static char hello[]=hello;
The output of printf(%s\n,hello); will be the same as that of
a) puts( hello);
b) puts(hello);
c) printf(%s\n,hello);
d) puts(hello\n);
e) All of Above
Ans : [e]
31 . Main()
{
int i = 257;
int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}
Ans:
11
32. Bitfields areused to
a) save time
b) save memory
c) change order of allocation of memory
d) none of the above
Ans : [a]

C-APTITUDE.
====================================================================================

32. Is there any difference between the two declarations,


1. int foo(int *arr[]) and
2. int foo(int *arr[2])
Ans:
No
34. Is the following code legal?
struct a
{
int x;
struct a b;
}
Ans:
No
35. ferror function is used to find _________________ errors
a) logical
b) file opening
c)data
d)all the above
ANS: [b]
36. What is output of the following sinpt?
main()
{
int a= 0;
int b = 20;
char x =1;
char y =10;
if(a,b,x,y)
printf("hello");
}
ANS:
hello
37. Is the following code legal?
struct a
{
int x;
struct a *b;
}
Ans:
Yes.

[ b]

C-APTITUDE.
====================================================================================

38. #define f(g,g2) g##g2 main()


{
int var12=100;
printf("%d",f(var,12));
}
Ans:
100
39. If a two dimensional array is used as a formal parameter, then
a) both the subscripts may be left empty
b) the first( row) subscript may be left empty
c) the first subscript must be left empty
d) both the subscripts must be left empty
Ans; a.
40. Is this code legal?
int *ptr;
ptr = (int *) 0x400;
Ans:
Yes
41. int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
Ans:
Runtime error
42. Printf can be implemented by using __________ list.
Ans:
Variable length argument lists
43. main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{

C-APTITUDE.
====================================================================================

printf(%d ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(%d ,*p);
p++;
}
}
Ans: Compiler error: lvalue required.
44. main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
Ans:
255
45 .The argument used to print the number of command line arguments
is a)printf(%d,argv);
b) printf(%d,argv[0]);
c) printf(%d,argc);
d) none
Ans: c
46.#include<stdio.h> main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
Ans:
Compiler Error

C-APTITUDE.
====================================================================================

48.
typedef enum errorType{warning, error, exception,}error;
main()
{
error g1;
g1=1;
printf("%d",g1);
}
Ans
Compiler error:
49. typedef struct error{int warning, error, exception;}error;
main()
{
error g1;
g1.error =1;
printf("%d",g1.error);
}
Ans:
[1]
50. The operator -> is same as the combination of the operators
a) * and.
b) & and .
c) * and
d) none of the above
Ans :[ a and c]
51. enum colors {BLACK,BLUE=100,GREEN}
main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}
Ans:
0..100..101
52. puts(argv[0])prints
a) the name of the source code file
b) the number of command line arguments
c) argv

C-APTITUDE.
====================================================================================

d)the name of the executable code file


Ans : [d]
53. #include<stdio.h>
main()
{
int a=2;
int b=4;
b=b<<a;
printf("%d\n",b);
}
What is output of the above snip?
54. #include<stdio.h>
main()
{
char *ptr="Ramco systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Ans: RunTime Error:
55 .main()
{
int x=10;
int y=15;
x=x++;
y=++y;
printf("x = %d y = %d\n",x,y);\
}
What is output of the following snipt write down with explanation ?
56. #include<stdio.h>
main()
{
int a[]={0,0x4,4,9};
int i=2;

C-APTITUDE.
====================================================================================

printf("%d\t%d",a[i],i[a]);
}
57. main()
{
const char *buf="Hello";
buf++;
printf("%s",buf);
}
What is output of the following snipt write down with explanation ?
58. .#define MAX(x,y) (x) >(y)?(x):(y)
main()
{
int i=10,j=5,k=0;
k= MAX(i++,++j);
printf("%d..%d..%d",i,j,k);
}
What is output of the following snipt write down with explanation ?
59. main()
{
enum _tag{ left=10, right, front=100, back};
printf("left is %d, right is %d, front is %d, back is
%d",left,right,front,back);
}
What is output of the following snipt write down with explanation ?

60 .#define PRINT(int) printf("int = %d ",int)


main()
{
int x,y,z;
x=03;y=02;z=01;
PRINT(x^x);
z<<=3;PRINT(x);
y>>=3;PRINT(y);

C-APTITUDE.
====================================================================================

}
What is output of the following snipt write down with explanation ?
61. What is the o/p of C program
int I = 55;
int char1 = 55 && 0x53;
int char2 = char1 + 20;
if (char1= = char2)
print(char1);
else
print(char2);
What is output of the following snipt write down with explanation ?
62.main()
{
char x[]="12345";
char *p;
p=x;
while(*p++!='\0')
printf("%c\n",*p);
}
What is output of the following snipt write down with explanation ?
63.main()
{
int i=3,j=4,k=6;
k=i&j&k;
printf("%d\n",k);
}
64.
main()
{
printf("%d\n",printf("%d\n",printf("hello\n")));
}
What is output of the following snipt write down with explanation ?

65
.main()

C-APTITUDE.
====================================================================================

{
int i=5;
printf("%d %d %d %d %d",++i,i++,i,--i,i--);
}
Ans: 5 3 3 3 5
66.
main()
{
char a[]="hellow";
char *b="hellow";
char c[10]="hellow";
printf("%d %d %d\n",sizeof(a),sizeof(b),sizeof(c));
}
Ans: 7 4 10
67 .main()
{
char a='abc';
char b[4]="abc";
printf("\n=%c\n=%c",a,*b);
}
68. Main()
{
printf("NULL= %u ""= %u\n",sizeof(NULL),sizeof(""));
}
Ans: NULL= 4 = 1 */
69.main()
{
int *ptr;
ptr=(int *)0xabcd;
*ptr=0xdcba;
printf("\n%x",*ptr);
}
Ans : run time error */
70.Main()
{
struct s.
{
int a;
long b;
}x;

C-APTITUDE.
====================================================================================

71.

union u
{
int a;
long b;
}y;
printf("%d %d\n",sizeof(x),sizeof(y) );
}
Ans: 8 4
f()
{
int a=2;
f1(a++);
printf("a=%d",a);
}
f1(int c)
{
printf("c=%d",c);
}
main()
{
f();
}
What is output of the following snipt write down with explanation ?

72. main()
{
struct samp
{
int a;
struct samp s;
}smp;
printf("%d",sizeof(smp));
}
What is output of the following snipt write down with explanation ?
73. main()
{
char *months[]={"jan","feb","mar"};
printf("\n size=%d",sizeof(months));

C-APTITUDE.
====================================================================================

}
What is output of the following snipt write down with explanation ?
74. fun(int *h,int *k)
{
h=100;
k=200;
}
main()
{
int i=1,j=2;
fun(&i,&j);
printf("%d %d",i,j);
}
75. void fun1();
void fun2();
main()
{
//printf("%d\n", a);
fun1();
fun2();
}
int a=10;
void fun1()
{
printf("%d ", a);
}
void fun2()
{
printf("%d ", a);
}
What is output of the following snipt write down with explanation ?
76.main()
{
char *month={"Jan", "FEB", "Mar"};
printf("%d", sizeof(month));
}
void tf(int *p1,int *p2)
{
p1=(int *)100;

C-APTITUDE.
====================================================================================

p2=(int *)200;
}
What is output of the following snipt write down with explanation ?
77. main()
{
int v1 = 1;
int v2 = 2;
tf(&v1,&v2);
printf("%d\n%d\n",v1,v2);
}
What is output of the following snipt write down with explanation ?
78. main()
{
int x=80;
x=x>>3;
printf("%d", x);
}
What is output of the following snipt write down with explanation ?
79. Main()
{
struct date
{
int hour, minute, second;
};
int x;
x = sizeof( struct date );
}
What is output of the following snipt write down with explanation ?
80.#define A 10
main()
{
int A;
scanf("%d", A);
}
What is output of the following snipt write down with explanation ?

C-APTITUDE.
====================================================================================

81.main()
{
int i = 1;
i=i<< 5 % 2;
printf("%d ", i);
}
What is output of the following snipt write down with explanation ?
82.main()
{
("%d %d %d\n",i,j,k); /* 4 2 3 */
}
83.void fun(int *p1, int *p2)
{
p1=(int *)100;
p2=(int *)200;
}
main()
{
int val1=1, val2=2;
fun(&val1, &val2);
printf("%d %d\n", val1, val2);
What is output of the following snipt write down with explanation ?

84. predict the output of the program


void main()
{
int const * p=5;
printf("%d",++(*p));
}
85. predict the output of the program
main()
{
static int var = 5;
printf("%d ",var--);
if(var)

C-APTITUDE.
====================================================================================
main();
}
86. Predict the output of the program
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
87. Predict the output
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);
}
88. predict the output

main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");

C-APTITUDE.
====================================================================================
break;
}
}
89. What is the output of the following program?
main()
{
unsigned int x = 0xffff;
~x;
printf ("%x", x);
}
90. What is the output of the following program?
main()
{
int a = -3, b = 2, c= 0, d;
d = ++a && ++b || ++c;
printf ("a = %d, b = %d, c = %d, d = %d", a, b, c, d);
}
91. What would be the output of this program?
main() {
int x = 20;
{
int x = 10;
printf ("%dn", x);
}
printf ("%d", x);
}
93 . What is the output of the following program?
main()
{
int x = 10;
printf ("%d %d", ++x, ++x);
}

C-APTITUDE.
====================================================================================

You might also like