c aptitude question with answer volume 4
113.Find the output
main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Answer:
hai
Explanation:
\n - newline
\b - backspace
\r - linefeed
114. Find the output
main()
{
int i=400,j=300;
printf("%d..%d");
}
Answer:
400..300
Explanation:
printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage values.
115. Find the output:
main()
{
char not;
not=!2;
printf("%d",not);
}
Answer:
0
Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.
116. Find the output
main()
{
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}
Answer:
A
Explanation:
Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.
117. Find the value :
main()
{
int i=5,j=10;
i=i&=j&&10;
printf("%d %d",i,j);
}
Answer:
1 10
Explanation:
The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.
118. main()
{
int i=4,j=7;
j = j || i++ && printf("YOU CAN");
printf("%d %d", i, j);
}
Answer:
4 1
Explanation:
The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to zero itself means that the expression’s truth value is 1. Because it is followed by || and true || (anything) => true where (anything) will not be evaluated. So the remaining expression is not evaluated and so the value of i remains the same.
Similarly when && operator is involved in an expression, when any of the operands become false, the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated.
false && (anything) => false where (anything) will not be evaluated.
119. Which is the output produced by the following program
main()
{
int n=2;
{
int n=2;
printf("%d %d\n", ++n, n*n);
}
a) 3,6 b) 3,4 c) 2,4 d) cannot determine
Answer : b) 3,4
120. What is the output of the following program? (. has been used to indicate a space)
main()
{
char s[]="Hello,.world";
printf(%15.10s",s);
}
a )Hello,.World...
b)....Hello,.Wor
c)Hello,.Wor....
d)None of the abov
main()
{
char s[]="Hello,.world";
printf(%15.10s",s);
}
a )Hello,.World...
b)....Hello,.Wor
c)Hello,.Wor....
d)None of the abov
Answer :
121.Find the output :
main()
{
int i=20,*j=&i;
f(i);
printf("%d",i);
printf("%d",i);
}
Answer :
122 . main()
{
int var=25,varp;
varp=&var;
varp=10;
fun(varp);
printf(%d%d",var,varp);
fun(varp);
printf(%d%d",var,varp);
}
choice : a}45,45 b}55,55 c} 20,55;
choice : a}45,45 b}55,55 c} 20,55;
Answer :
123. u r given two statements
a=(10.15);
b=10,15;
if they are executed what is the output if printf("%d%d",a,b);
a)10,15 b)15,10 c)10,10 d)15,15
a=(10.15);
b=10,15;
if they are executed what is the output if printf("%d%d",a,b);
a)10,15 b)15,10 c)10,10 d)15,15
Answer : a
124. main
{
{
int x=1,y=2,z=3;
x=y==z;
printf(x);
}
Answer :
125. Find the output for the following C program
main()
{
main()
{
int x,j,k;
j=k=6;x=2;
x=j*k;
printf("%d", x);
j=k=6;x=2;
x=j*k;
printf("%d", x);
}
Answer : .36
126. Find the output for the following C program
main()
{
main()
{
intx=2,y=6,z=6;
x=y==z;
printf(%d",x)
}
x=y==z;
printf(%d",x)
}
Answer :
127. Comment:
a=(10,15), b=10,15
what are the values of a & b in ANSI C
Answer :15,10
128. main()
{
int x=10,y=15,z=16;
x=y=z;
printf("%d",x);
}
Answer : 0
128. Find the output:
main()
{
int x==2
{
x==x+2
}
printf("%d",x);
}
Answer :
129.Find the output:
void main()
{
int a=3,c=4,c=5;
a=b+c;
c=a+b;
b=a+c;
printf("%d %d %d",a+b,b+c,c+d);
a=b*c;
c=a*b;
printf(%d %d",a.c);
}
Answer :
130. Which of the choices is true for the mentioned declaration ?
const char *p;
and
char * const p;
a) You can't change the character in both
b) First : You can't change the characterr &
Second : You can;t change the pointer
c) You can't change the pointer in both
d) First : You can't change the pointer &
Second : You can't chanage the character
e) None
Answer : b ( check it)
131.comment:
{
float a,b,c;
if(b*b-4*a*c)=0.0printf(“the roots r equal”);
}
Answer :
132.
main()
{
int x=14,y=10,z=3;
x*=y+1+z;
printf(“%d”,x);
}
what is the value of x?
Answer :
133.const char *
char * const
What is the differnce between the above two?.
Answer :
134. char *p=(char *)10
output ?
135.
main()
{
char a,b;
printf("%d%d%d%d",sizeof('a'),sizeof(NULL),sizeof(b),sizeof(main));
}
Answer :
136.
main()
{
printf("%u",main);
}
what will be the output?
Answer:
137. Find the output:
main()
{
printf("Enter two values a and b:"):
scanf("%d%d",a,b);
printf("%d+%d=%d",a,b,a+b);
}
Output is ?
Answer :
138.What is the output
Intcount=10,sum=0,*temp;
Temp=&count;
Sum=? &count;( It was actually given temp=? &count;
which is probably wrong)
Printf(“sum=%d count= %d temp=%d “,sum,count,*temp);
Answer :C (most expected answer ,check it)
139.Which one has no L-Value
[i] a[i]
[ii] i
[iii] 2
[iv] *(a+i)
Answer : [iii]
140.void main()
{
char *p=””s”Hello”;
printf(“%s”,p);
}
what is the o/p?
a.sHello
b.s
c.Hello
d.error
Answer :
141.Find the output
#include<stdio.h>
main()
{
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
Answer :
142.Find the o/p:
a=(10,15)
b=10,15
what are the values of a & b in ANSI C
Answer : 15,10
143.
main(){
int x=10,y=15,z=16;
x=y==z;
printf("%d",x);
Answer :0
144. What is the o/p of this program
#include<stdio.h>
int main()
{
char value = '\123';
printf("0/oC \n", value);
return 0;
}
A)ASCII Valueof121
8)1
C)3
Answer :
145.What is the output of the following code snippetmain(){ printf(5+"Fascimile");}Answer :. mile
146.output of the program
main()
{
printf("%c","abcdef"[4]);
}
Answer :
147.output:
main()
{
scanf”%c [^a]”a);
}
Answer :
148. printf('%d',printf('hello'));
Answer :
MACROS
149. Find the output
#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer:
64
Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64
150. Find the output
#define VALUE 1+2
main()
{
printf("%d and %d\n",VALUE/VALUE,VALUE*3);
}
Answer : 5,7
151. Find the output
#define hello(x,y)
printf(#expr"%d",expr);
main()
{
float x=1,y=2;
expr=x/y;
hello(expr);
}
Answer :
152.Analyse
# define TRUE 0
some code
while(TRUE)
{
some code
}
# define TRUE 0
some code
while(TRUE)
{
some code
}
Answer :
This won't go into the loop as TRUE is defined as 0
This won't go into the loop as TRUE is defined as 0
153. What is the effect of the following program segment?
#define MAX 50
main()
{
int a[MAX], i, j, temp;
for( i=O;i<MAX-l;++i)
if(a{i}>a{i+l})
temp = a[i]; a[i]=a[i+l]; a[i + 1] =temp;
}
A)Arrange the elements ofarray a in ascending order.
B)Counts the number of elements of a greater than its first element.
C)Reverses the numbers stored in the array.
D)Puts the largest value in the last array position.
Answer :
154. Find the result:
#define prod((a>b)?a*a:b*b)
main()
{
int p==0,q==-1;
prod(p++,q++)
}
Answer :
Answer :
155. What are the values printed by the following
program?
#define dprint(expr) printf(#expr "=%d\n",expr)
main()
{
int x=7;
int y=3;
dprintf(x/y);
}
Choice:
a) #2 = 2 b) expr=2 c) x/y=2 d) none
Answer: c
156. What is the output of the following problem ?
#define INC(X) X++
main()
{
int X=4;
printf("%d",INC(X++));
}
a)4 b)5 c)6 d)compilation error e) runtime error
Answer : d
157. Consider the following function written in c:
#define NULL 0
char *index(sp,c)
register char *sp,c;
{
do {
if(*sp == c)
return (sp);
} while (*sp++);
return NULL;
}
The first argument sp, is a pointer to a C string. The second argument, c, is a character. This function scarches for the character c, in the string. If it is found a pointer to that location is returned else NULL is returned.
This function works
a) Always
b) Always, but fails when the first byte contains the character c
c) works when c is a non NULL character only
d) Works only when the character c is found in the string
Answer : a
158. Find the output
# define cube(x) x * x * x
main()
{
int a=3;
cube(a++);
}
Answer :
0 comments:
Post a Comment