Cjet C Apptitude-1
Cjet C Apptitude-1
====================================================================================
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]
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.
====================================================================================
[ c]
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.
====================================================================================
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.
====================================================================================
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.
====================================================================================
.
27.
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.
====================================================================================
[ b]
C-APTITUDE.
====================================================================================
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.
====================================================================================
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 ?
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 ?
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.
====================================================================================