Capgemini and Hexaware Pseudo Code Questions: Study Material 2020-2021 Batch

Capgemini and Hexaware Study Material: Last year placement papers:

Capgemini Study Material 2020-2021 Batch includes Capgemini Aptitude Questions, Capgemini Logical Reasoning Questions, Capgemini Technical Programming Questions, Capgemini Pseudo Code Questions with Explanation, Capgemini Sample Verbal Ability Questions, C Programming MCQs

Must Read:

Capgemini Pseudo Code Questions: Capgemini Study Material

Capgemini Pseudo Code Questions with Explanation [50+]
1. What will be the output of following code :

int A[5][5], k, j;
for(k = 0; k<5; ++k)
for(j=0; j<5; j++)
A[k][j] = A[j][k];

A. It transposes the given matrix A
B. It does not alter the given matrix.
C. It makes the given matrix A, symmetric
D. None of the above.

Ans. A

Explanation : Above logic is to deduce the transpose of a matrix.

2. What is the output of given code :

#include<stdio.h>
int main()
{
long double a;
long double b;
int arr[sizeof(!a+b)];
printf(“%d”,sizeof(arr));
}

A. Run time Error
B. 32
C. 64 with warning
D. No output

Ans. C

Explanation : Size of long double in GCC Linux basede compilers : 16

Size of Integer : 4

So, Size of !(a+b) : 16

Integer array of size 16 : 16 * 4 => 64
3. Which of the following statements is true regarding, Auto Storage Class ?

A. It is used to give a reference of a global variable that is visible to all program files.
B. It instructs the compiler to keep a local variable in existence during the lifetime of a program.
C. It is the default storage class for all local variables.
D. It is used to define local variables that should be stored in a register.

Ans. C

4. What is the output of given code :

#include<stdio.h>
int main()
{
int x =4, y = 0;
int z;
z = (y++, y);
printf(“%d\n”, z);
return 0;
}

A. 1
B. 0
C. Undefined Behavior due to order of evaluation can be different.
D. Compilation Error

Ans. A

Explanation : Consider the line : z = (y++, y)

So, at first z is assigned with y++ after this statement y is incremented to 1.

Next expression is z = y, so z = 1.

Capgemini Pseudo Code Questions
5. What is the output of given code (Input : 1.45):

#include<stdio.h>
int main()
{
int ch;
print(“Enter a value between 1 & 2”);
scanf(“%d”, &ch);
switch(ch, ch+1)
{
case 1 :
printf(“1\n”);
break;
case 2 :
printf(“2\n”);
break;
default :
printf(“3\n”);
}

A. 1
3
B. Error : Undefined condition in switch
C. 2
D. No output

Ans. C

Explanation : For ch = 1.45,

switch() will be executed for ch=2, and hence 2 will be printed as o/p.

6. What is the output of given code for input 134 :

int fun1(int num)
{
static int a =0;
if (num>0)
{
a=a+1;
fun1(num/10);
}
else
{
return a;
}
}

A. 2
B. 3
C. Runtime Error
D. None of these

Ans. B

Explanation : Just a given recursive solution. Try dry running the code.

Capgemini Pseudo Code Questions
7. What will be output of given pseudo code for input 7 :

1. read the value of n
2. set m=1,t=0
3. if m >= n
4. go to line 9
5. else
6. t=t+m
7. m+=1
8. go to line 3
9. display T
10. stop

A. 32
B. 76
C. 56
D. 28

Ans. D

Explanation : Simple code, try dry run.

8. What will be output of given pseudo code for input 2 :

int fun(int n)
{
if(n == 4)
return n;
else
return 2*fun(n+1);
}

A. 4
B. 8
C. 16
D. Error

Ans. C

Explanation : 2*2*4
9. What will be output of given pseudo code :

int i=5, j=7;
if ( i+j> 5)
j = i+2;
if ( j<5 )
print(i)
else
print(j)
else
print(i+1)

A. 12
B. 5
C. 7
D. 6

Ans. C

Explanation : Simple Code just dry run.

10. What will be output of given pseudo code :

int j=41, k= 37
j=j+1
k=k-1
j=j/k
k=k/j
print(j,k)

A. 42 36
B. 36 1
C. 1 1
D. 1 36

Ans. D

Explanation :

j = 41+1 => 42

k = 37-1 => 36

j = 42/36 => 1

k = 36/1 => 36

1, 36.
11. What will be output of given pseudo code :

#include<stdio.h>
using namespace std;
int main()
{
int a =0,b=1,c=2;
*( ( a+1==1) ? &b : &a)= a? b : c;
printf(“%d, %d, %d \n”, a , b, c );
return 0;
}

A. 0 1 2
B. 0 2 0
C. 0 2 2
D. Error

Ans. C

Explanation :

To solve this code, you need to have good understanding of ternary operator.

(0 + 1 == 1) // True

So, LHS becomes *(&b) // value at address of b.

Now, a? b : c => 0?1:2 So, RHS leaves 2

On comparing, *(&b) = 2 or b =2

So, a=0, b=2, c=2

12.
integer a = 40, b = 35, c = 20, d = 10
Comment about the output of the following two statements:

print a * b / c – d
print a * b / (c – d)

A. Differ by 80
B. Same
C. Differ by 50
D. Differ by 160

Ans. A

Explanation :

The first expression, will be read as : (40 * 35 / 20) – 10 => 60

The second expression will be read as : (40 * 35)/(20-10) => 140
13. integer a = 60, b = 35, c = -30
What will be the output of the following two statements:
print ( a > 45 OR b > 50 AND c > 10 )
print ( ( a > 45 OR b > 50 ) AND c > 10 )
A. 0 and 1
B. 0 and 0
C. 1 and 1
D. 1 and 0
Ans. D
Explanation : Above code is pretty straight forward as logical operators are provided.
14. What will be the output of the following code :
integer a = 984, b=10
float c
c = a / b
print c
A. 984
B. 98.4
C. 98
D. Error
Ans. C
Explanation : Answer will be like 98.0000, here C is the most suited option.

Capgemini Pseudo Code Questions
15. Consider the following code:
if (condition 1) {
if (condition 2)
{ // Statement A } else
if (condition 3)
{ // Statement B} else
{// Statement C } else
if (condition 4)
{// Statement D}
else
{// Statement E}
}
Which of the following condition will allow execution of statement A?

A. NOT(condition2) AND NOT(condition3)
B. condition1 AND condition4 AND NOT(condition2) AND NOT(condition3)
C. condition1 AND condition2 AND condition4
D. NOT(condition1) AND condition2 AND NOT(condition4)

Ans. C

16. What will be the output of following code :

#include<stdio.h>
int main()
{
int num = 8;
printf (“%d %d”, num << 1, num >> 1);
return 0;
}

A. 8 0
B. 0 0
C. 16 4
D. Error : Can’t Perform operation

Ans. C

Explanation : ‘<<‘ This is the left shift operator. It takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. ‘>>’ This is the right shift operator.

8 in binary form : 00001000

Performing Left Shift (<<) : 00010000 => 16

Performing Right Shift (>>) : 00000100 => 4
17. What will be the output of following code :

#include<stdio.h>
int main(){
int i = 16;
i =! i > 15;
printf(“i = %d”,i);
return 0;
}

A. i = -1
B. i = 0
C. i = 1
D. Error : Undefined operation

Ans. B

Explanation : Consider the statement i =! i > 15 as :

i = negation of ( Is i > 15 )

i = negation of ( 1 ) // 1 denotes True

So, i becomes 0.

18. What will be the output of following code :

#include<stdio.h>
int main()
{
int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
printf(“%d”,sizeof(x));
return 0;
}

A. 40
B. 10
C. 20
D. Error

Ans. A

Explanation : Above is the array of 10 integers and size of each integer is 4 bytes. So, 4 * 10 = 40.
19. What will be the output of following code :

#include<stdio.h>
int main()
{
int x = 2;
(x & 1) ? printf(“true”) : printf(“false”);
return 0;
}

A. true
B. false
C. 0
D. Error

Ans. B

Explanation : Above code is easy if you know the working of ternary operators. 2 & 1 is 0, so “false” is the answer.

20. What will be the output of following code :

#include<stdio.h>
int main()
{
int a = 4, b = 2;
printf(“a^b = %d”, a^b);
return 0;
}

A. 4
B. 1
C. 0
D. 6

Ans. D

Explanation : Above code is just for performing the xor operation between two variables.

Capgemini Pseudo Code Questions
21. What will be the output of following code :

#include<stdio.h>
int main()
{
int a = 4, b = 2;
printf(“a|b = %d\n”, a|b);
return 0;
}

A. 4
B. 1
C. 0
D. 6

Ans. D

Explanation : Above code is just for performing the Logical OR operation between two variables.

22. What will be the output of following code :

#include<stdio.h>
int main()
{
int a = NULL – true;
printf(“%d”,a);
return 0;
}

A. -1
B. Garbage value
C. 0
D. Error

Ans. -1

Explanation : In programming terminology, NULL denotes 0 and true denotes 1, So 0-1=> -1.
23. What will be the output of following code :

#include<stdio.h>
int x = 0;
int main(){
if(x == x)
printf(“if”);
else
printf(“else”);
return 0;
}

A. Two same variables can not be compared
B. ifelse
C. else
D. if

Ans D

Explanation : Above code involves simple comparison

24. What will be the output of following code :

#include<stdio.h>
#define FALSE -1
#define NULL 0
#define TRUE 1

int main(){
if(NULL)
printf(“NULL”);
else if(FALSE)
printf(“TRUE”);
else
printf(“FALSE”);
return 0;
}

A. TRUE
B. FALSE
C. NULL
D. Error

Ans. A
25. What will be the output of following code :

#include<stdio.h>
int main(){
int i;
if(true)
printf(“work”);
else
printf(“not work”);
return 0;
}

A. work
B. not work
C. compiler error
D. runtime error

Ans. A

Explanation : If condition satisfies, hence work will be printed.

26. What will be the output of following code :

#include<stdio.h>
int main()
{
if(printf(“0”))
printf(“inside if block”);
else
printf(“inside else block”);
return 0;
}

A. inside else block
B. 0
C. 0inside if block
D. Error – If can not have print statement

Ans. C

Explanation : C is the correct answer as, firstly, ‘0’ will be printed and then since the condition gets fulfilled, another message ‘inside if block’ will be printed as well.
27. What will be the output of following code :

#include<stdio.h>
int main(){
int i = 5, j = 4;
if(!printf(“”))
printf(“%d %d”, i, j);
else
printf(“%d %d”, i++, ++j);
return 0;
}

A. 5 5
B. 5 4
C. 5 6
D. 6 6

Ans. B

Explanation : 5 4 will be the output as the statements inside if block will be executed. This is because :

if(printf(“”)) is false(as it is not printing any mess.) and

if( ! printf(“”)) is true

However, if there was any text written inside “” in printf(“”), then if(printf(“”)) would have become true.

28. What will be the output of following code :

#include<stdio.h>
int main()
{
int i = 25;
if(i == 25);
i = 50;
if(i == 25)
i = i + 1;
else
i = i + 1;
printf(“%d”, i);
return 0;
}

A. 51
B. 25
C. 50
D. None of these

Ans. A

Explanation : 51 is the correct answer as the first if-condition is true. So, i becomes 50. Again the second if condition is false, so corresponding else to that if statement will be executed, so i = 50 + 1 .
29. What will be the output of following code :

#include<stdio.h>
int main()
{
if(sizeof(0))
printf(“Hai”);
else
printf(“Bye”);
return 0;
}

A. 2
B. Bye
C. Runtime Error
D. Hai

Ans. D

Explanation : sizeof(0) is 4 hence it is true, Hai will be printed as the message.

Capgemini Pseudo Code Questions

30. What will be the output of following code :

#include<stdio.h>
int main()
{
if(sizeof(‘\0’))
printf(“inside if block”);
else
printf(“inside else block”);
return 0;
}

A. inside if block
B. inside else block
C. Null Pointer Exception
D. None of these

Ans. A

Explanation : A is correct as sizeof(‘\0’) will return 1, hence if condition is true.
31. What will be the output of following code :

#include<stdio.h>
int main()
{
int i = 65;
switch(i)
{
case 65:
printf(“Integer 65”);
break;
case ‘A’:
printf(“Char 65”);
break;
default:
printf(“Bye”);
}
return 0;
}

A. Integer 65
B. Char 65
C. Bye
D. Error : Duplicate Values

Ans. D

Explanation : D is correct as case ‘A’ and case 65 both are same thing and cases can not have duplicate values.

32. What will be the output of following code :

#include<stdio.h>
int main()
{

switch(2/3)
{
case 1:
printf(“case 1 executed “);

case 2:
printf(“case 2 executed “);
break;
default:
printf(“Default block executed”);
}
return 0;
}

A. case 1 executed
B. case 2 executed
C. Default block executed
D. Error : Switch statements can not hold

Ans. C

Explanation : C is correct as none of the above cases follow the condition so default block will be executed.
33. What will be the output of following code :

#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case i:
printf(“case 1 executed”);
break;
case i + 1;
printf(“case 2 executed”);
break;
default:
printf(“default block executed”);
break;
}
return 0;
}
A. case 1 executed
B. case 2 executed
C. default block executed
D. Error : i is not usable

Ans. D

Explanation : Above code will produce error: the value of ‘i’ is not usable in a constant expression.

34. What will be the output of following code :

#include<stdio.h>
int main(){
while(printf(“%d”, 5) < 4)
printf(“Loop “);
return 0;
}

A. Loop Loop Loop Loop Loop
B. Infinite loop
C. 5Loop 5Loop 5Loop 5Loop 5Loop
D. None of these

Ans. B

Explanation : Above code will result in an infinite loop as condition will always be true.
35. What will be the output of following code :

#include<stdio.h>
#define NULL 0
int main()
{
while (NULL == 0)
{
printf(“Loop”);
break;
}
return 0;
}

A. Loop
B. Null
C. 0
D. Error : Null can not be compared

Ans. A

Explanation : Null is equivalent to 0. And hence, Option A is correct.

36. What will be the output of following code :

#include<stdio.h>
int main(){
float ft = 7.5;
while(ft)
{
printf(“Loop”);
ft = ft – .5;
if(ft == 5.0f)
break;
}
return 0;
}

A. LoopLoopLoopLoopLoop
B. Loop
C. No output
D. None of these

Ans. A

Explanation : while loop will run for 5 times, i.e for the values 7.5, 7.0, 6.5, 6.0, 5,5. Hence, printing “Loop” for 5 times.
37. What will be the output of following code :

#include<stdio.h>
int main()
{
while(!!7)
printf(“Hai”);
return 0;
}

A. Hai
B. HaiHai
C. Infinite loop
D. None of these

Ans. C

Explanation : Above code will result in infinite loop.

38. What will be the output of following code :

#include<stdio.h>
int main(){
while(!printf(“awesome”));
return 0;
}

A. awesome
B. Error
C. Infinite loop
D. None of these

Ans. A

Explanation : Above code will just print “awesome” as the message.

 

Leave a Comment