c aptitude question with answer volume 7
102. For the following statement find the values generated for p and q?
int p = 0, q =1;
p = q++;
p = ++q;
p = q--;
p = --q;
The value of p and q are:-
a) 1,1 b) 0,0 c) 3,2 D) 1,2
Answer :
103. output of the program?
main()
{
int a=2, b=3;
printf(" %d ", a+++b);
}
Answer : 5
explanation: here it evaluates as a++ + b.
104. #include<stdio.h>
void main(void);
void main(void)
{
int i=100,j=20;
i++=j;
i*=j;
printf("%d\t%d\n",i,j);
}
Answer :
105. What will be the result of executing the following statement
int i=10;
printf("%d %d %d",i,++i,i++);
a).10 11 12
b).12 11 10
c).10 11 11
d).result is OS dependent
e).result is compiler dependent
Answer : e
STRUCTURES & UNIONS
106. struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Is the above assignment to pointer is correct or wrong ?
Answer : Wrong
107. struct point
{
struct point *next;
int data;
}x;
main()
{
int i;
for(x=p;x!=0;)
x=x->next,x++;
freelist(x);
}
freelist(x)
{
free(x);
return
}
find error?
Answer :
108. What is the size of ptr1 and ptr2.
struct x
{
int j;
char k[100];
unsigned i;
};
int *ptr1:
struct X *ptr2;
A) Same depending on the model used
B) 2,104
C) 2, Undefined for memory is not allocated
D) 2,4
Answer :
109. what is the output of the program?
#include<stdio.h>
main()
{
struct s1 {int i; };
struct s2 {int i; };
struct s1 st1;
struct s2 st2;
st1.i =5;
st2 = st1;
printf(" %d " , st2.i);
}
Answer : nothing (error)
explanation: diff struct variables should not assigned using "=" operator.
110. #include<stdio.h>
void main(void);
void main(void)
{
struct s
{
int x;
float y;
}s1={25,45.00};
union u
{
int x;
float y;
} u1;
u1=(union u)s1;
printf("%d and %f",u1.x,u1.y);
}
Answer :
111. #include<stdio.h>
void main(void);
typedef struct NType
{
int i;
char c;
long x;
} NewType;
void main(void)
{
NewType *c;
c=(NewType *)malloc(sizeof(NewType));
c->i=100;
c->c='C';
(*c).x=100L;
printf("(%d,%c,%4Ld)",c->i,c->c,c->x);
}
Answer :
112. struct adr {
char *name;
char *city;
int zip;
};
struct adr *adradr;
which are valid references?
i) adr->name X
ii) adradr->name
iii) adr.zip X
iv) adradr.zip
Answer :
113. main()
{
union u
{
struct s
{
char c1, c2;
};
long x;
float y;
};
u example ;
example.s.c1 = 'a' ;
example.s.c2 = 'b' ;
example.x = 5;
printf("%c %c %d", example.s.c1, example.s.c2, example.x);
}
(a). a b 5
(b). 0 0 5
(c). garbage garbage 5 (Correct)
(d). error
Answer :
FILES
114. main()
{
FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)
}
Find the Error, If Any?
Answer :. no error. But It will over writes on same file.
OPERATORS
115. '-'=45 '/'=47
printfr(%d/n,'-','-','-','-','/','/','/');
o/p =?
Answer :
116. if x is even, then
I) (x%2)=0
II )x &1 !=1
is the above 2 statements true ??
Answer :
117. a=0;
b=(a=0)?2:3;
a) What will be the value of b? why
b) If in 1st stmt a=0 is replaced by -1, b=?
c) If in second stmt a=0 is replaced by -1, b=?
Answer :
118. signed int a=-1;
int b;
a=~a;
b=~0;
a=~a;
printf("%d %d",a,b);
a. -1 -1
b. -1 1
c. -1 0
d. 1 1
Answer :
119. main()
{
int a=10,b=8,c=3;
printf("%d %d %d %d ",a,a=9,a<b);
}
a. 10 9 0 3
b. 10 9 0 Garbage value
c. 9 9 1 3
d. 9 9 0 Garbage Value
Answer :
120. #include<stdio.h>
#include<conio.h>
main()
{
int i=-3,j=2,k=0,m;
m=++j && ++i || ++k;
printf("%d %d %d %d ",i,j,k,m);
getch();
}
a. -2 3 1 1
b. -2 3 1 0
c. -2 3 0 1
d. -2 3 0 0
Answer :
121. printf("%u",-1)
what is the value?
a. -1 b. 1 c. 65336 d. --
Answer :
(maxint value-1 I think, check for the answer)
122. int x=2;
x=x<<2;
printf("%d ",x);
Answer : 8;
123. int a[]={0,0X4,4,9}; /*some values are given*/
int i=2;
printf("%d %d",a[i],i[a]);
what is the value???
Answer : (may be error)
124. #include<stdio.h>
void main(void)
{
int y,z;
int x=y=z=10;
int f=x;
float ans=0.0;
f *=x*y;
ans=x/3.0+y/3;
printf("%d %.2f",f,ans);
}
Answer :
125. #include<stdio.h>
void main(void);
void main(void)
{
int var1,var2,var3,minmax;
var1=5;
var2=5;
var3=6;
minmax=(var1>var2)?(var1>var3)?var1:var3:(var2>var3)?var2:var3;
printf("%d\n",minmax);
}
Answer :
ARRAYS
126. what is the o/p of the program
main()
{
int rows=3,colums=4;
int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;i<rows;i++)
for(j=0;j<colums;j++)
if(a[k][j]<k) k=a[i][j];
printf("%d\n",k);
}
Answer :
127. #include<stdio.h>
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));
}
Answer : 3 3
128. main()
{
int mat[3][3] = { 1,2,3,4,5,6,7,8,9 };
int i, j;
for ( i = 2; i >= 0 ; i-- )
for ( j = 2; j >= 0 ; j-- )
printf("%d", *(*mat+j)+i);
}
(a). 9 8 7 6 5 4 3 2 1
(b). 1 2 3 4 5 6 7 8 9
(c). 9 6 3 8 5 2 7 4 1
(d). None of the above
Answer : c
129. main()
{
int x[]={0,0,0,0,0}
for(i=1;i<=4;i++)
x[x[i]]++;
for(i=0;i<5;i++)
printf(" %d",a[i]);
}
(i) 00000
(ii)11111
(iii)50000
(iv)12345
Answer :
130. int *num={10,1,5,22,90};
main()
{
int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
print the value of i, and q-p, and some other operations are there.
}
how the values will change??
Answer :
131. #include<stdio.h>
void main(void);
void main(void)
{
char numbers[5][6]={"Zero","One","Two","Three","Four"};
printf("%s is %c",&numbers[4][0],numbers[0][0]);
}
Answer :
132. int i, b[] = {1, 2, 3, 4, 5}, *p;
p = b;
++*p;
p += 2;
I) What is the value of *p;
a) 2 b) 3 c) 4 d) 5
Answer :
II)What is the value of (p - (&p - 2))?
a) b) 2 c) d)
Answer :
133. char name[] = {'n', 'a', 'm', 'e'}
printf ("name = \n%s", name);
a) name =name
b) name = followed by funk characters
c) name = \nname
d) none
Answer :
134. main (x, y)
int x, char *y[];
{
printf ("%d %s", x, y[1]);
}
output when invoked as
prog arg1
a. 1 prog
b. 1 arg1
c. 2 prog
d. 2 arg1
Answer :
135. what would the following program results in
main()
{
char p[]="string";
char t;
int i,j;
for(i=0,j=strlen(p);i<j;i++)
{
t=p[i];
p[i]=p[j-i];
p[j-i]=t;
}
printf("%s",p);
}
a)will print:string
b)will not print anything since p will be pointing to a null string
c)will print:gnirtS
d)will result in a complication error
e)will print invallid characters(junk)
Answer :
136. What will be the result of the following program
main()
{
char *x="String";
char y[] = "add";
char *z;
z=(char *) malloc(sizeof(x)+sizeof(y)=1);
strcpy(z,y);
strcat(z,y);
printf("%s+%s=%s",y,x,z);
}
a)Add+string=Add string
b)syntax error during compilation
c)run time error/core dump
d)add+string=
e)none
Answer : e
MISCELLANEOUS
137. main()
{
char *s;
s="hot java";
strcpy(s,"solarrs java")
}
Answer :
138. main()
{
printf("hot java");
fork()
exit(0);
}
1. when redirected to a sreen what will be printed?
2 when redirected to file what will be printed?
Answer :
139.
#include<stdio.h>
#include<conio.h>
int main()
{
char far* str,*str1;
printf("%d %d",sizeof(str),sizeof(str1));
getch();
}
a. 1 1
b. 4 4
c. 4 2
d. 1 4
Answer :
140. #include<stdio.h>
#include<conio.h>
main()
{
printf("%d %d %d",sizeof(3.2),sizeof(3.2f),sizeof(3.2l));
}
a. 8 8 10
b. 4 4 8
c. 8 4 8
d. 8 4 10
Answer :
0 comments:
Post a Comment