Bank exam questions and answers

Group exam questions and answers

Technical questions and answers

1. What will be output of following c code?

#include
int main(){
int x=011,i;
for(i=0;i printf("Start ");
continue;
printf("End");
}
return 0;
}
Output: Start Start Start Explantion: 011 is octal number. Its equivalent decimal value is 9. So, x = 9 First iteration: i = 0 i < x i.e. 0 < 9 i.e. if loop condition is true. Hence printf statement will print: Start Due to continue keyword program control will come at the beginning of the for loop and value of variable i will be: i += 3 i = i + 3 = 3 Second iteration: i = 3 i < x i.e. 3 < 9 i.e. if loop condition is true. Hence printf statement will print: Start Due to continue keyword program control will come at the beginning of the for loop and value of variable i will be: i += 3 i = i + 3 = 6 Third iteration: i = 3 i < x i.e. 6 < 9 i.e. if loop condition is true. Hence printf statement will print: Start Due to continue keyword program control will come at the beginning of the for loop and value of variable i will be: i += 3 i = i + 3 = 9 fourth iteration: i = 6 i < x i.e. 9 < 9 i.e. if loop condition is false. Hence program control will come out of the for loop.
2. What will be output of following c code?



#include
int main(){
static int i;
for(++i;++i;++i) {
printf("%d ",i);
if(i==4) break;
}
return 0;
}
2015-03-07 00:00:00
3. What will be output of following c code?

#include
int main(){
for(;;) {
printf("%d ",10);
}
return 0;
}
Output: Infinite loop Explanation: In for loop each part is optional.
4. What will be output of following c code?

#include
#define p(a,b) a##b
#define call(x) #x
int main(){
do{
int i=15,j=3;
printf("%d",p(i-+,+j));
}
while(*(call(625)+3));
return 0;
}
Output: 11 Explanation: First iteration: p(i-+,+j) =i-++j // a##b =i - ++j =15 – 4 = 11 While condition is : *(call(625)+ 3) = *(“625” + 3) Note: # preprocessor operator convert the operand into the string. =*(It will return the memory address of character ‘\0’) = ‘\0’ = 0 //ASCII value of character null character Since loop condition is false so program control will come out of the for loop
5. What will be output of following c code?

#include
int i=40;
extern int i;
int main(){
do{
printf("%d",i++);
}
while(5,4,3,2,1,0);
return 0;
}
Output: 40 Explanation: Initial value of variable i is 40 First iteration: printf function will print i++ i.e. 40 do - while condition is : (5,4,3,2,1,0) Here comma is behaving as operator and it will return 0. So while condition is false hence program control will come out of the for loop.
6. What will be output of following c code?

#include
int main(){
int i;
for(i=10;i<=15;i++){
while(i){
do{
printf("%d ",1);
if(i>>1)
continue;
}while(0);
break;
}
}
return 0;
}

Output: 1 1 1 1 1 1 For loop will execute six times. Note: continue keyword in do-while loop bring the program its while condition (while(0)) which is always false.
7. What will be output of following c code?

#include
int main(){
int x=123;
int i={
printf("c" "++")
};
for(x=0;x<=i;x++){
printf("%x ",x);
}
return 0;
}
Output: c++0 1 2 3 Explanation: First printf function will print: c++ and return 3 to variable i. For loop will execute three time and printf function will print 0, 1, 2 respectively.
8. What will be output of following c code?

#include
extern int x;
int main(){
do{
do{
printf("%o",x);
}
while(!-2);
}
while(0);
return 0;
}
int x=8;
Output: 10 Explanation: Here variable x is extern type. So it will search the definition of variable x. which is present at the end of the code. So value of variable x =8 There are two do-while loops in the above code. AS we know do-while executes at least one time even that condition is false. So program control will reach at printf statement at it will print octal number 10 which is equal to decimal number 8. Note: %o is used to print the number in octal format. In inner do- while loop while condition is ! -2 = 0 In C zero means false. Hence program control will come out of the inner do-while loop. In outer do-while loop while condition is 0. That is again false. So program control will also come out of the outer do-while loop.
9. What will be output of following c code?

#include
int main(){
int i=2,j=2;
while(i+1?--i:j++)
printf("%d",i);
return 0;
}
Output: 1 Explanation: Consider the while loop condition: i + 1 ? -- i : ++j In first iteration: i + 1 = 3 (True) So ternary operator will return -–i i.e. 1 In c 1 means true so while condition is true. Hence printf statement will print 1 In second iteration: i+ 1 = 2 (True) So ternary operator will return -–i i.e. 0 In c zero means false so while condition is false. Hence program control will come out of the while loop.
10. What will be output of following c code?


#include
int main(){
int i,j;
i=j=2,3;
while(--i&&j++)
printf("%d %d",i,j);
return 0;
}
Output: 13 Explanation: Initial value of variable i = 2 j = 2 Consider the while condition : --i && j++ In first iteration: --i && j++ = 1 && 2 //In c any non-zero number represents true. = 1 (True) So while loop condition is true. Hence printf function will print value of i = 1 and j = 3 (Due to post increment operator) In second iteration: --i && j++ = 0 && 3 //In c zero represents false = 0 //False So while loop condition is false. Hence program control will come out of the for loop.
div itemprop="description">AptTree.com is enhanced solution for learning and training all categories of Group&bank Questions and Answers.
Date published: 01/01/2015
5 / 5 stars