[go: up one dir, main page]

0% found this document useful (0 votes)
12 views7 pages

Accenture Psedocode - 8

Uploaded by

nilesh.k0901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Accenture Psedocode - 8

Uploaded by

nilesh.k0901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Which combination of the integer variables x, y and z makes the variable a get the value 4 in
the following expression?
a = (x > y)? ((x > z)? x : z): ((y > z)? y : z)
A) x = 3, y = 4, z = 2
B) x = 6, y = 5, z = 3
C) x = 6, y = 3, z = 5
D) x = 5, y = 4, z = 5
Answer A
20. What is the value printed by the following program
int f(int *a, int n)
{
if(n <= 0) return 0;
else if(*a % 2 == 0) return *a + f(a+1, n-1);
else return *a - f(a+1, n-1);
}
int main()
{
int a[] = {12, 7, 13, 4, 11, 6};
printf("%d", f(a, 6));
getchar();
return 0;
}
A) -9
B) 5
C) 15
D) 19
Answer C

2. Consider the following C program:


#include <stdio.h>
int counter = 0;
intcalc (int a, int b) {
int c;
counter++;
if (b==3) return (a*a*a) ;
else {
c = calc (a, b/3) ;
return (c*c*c) ;
}
}
int main () {
calc (4, 81);
printf ("%d", counter) ;
}
The output of this program is ______.
A) 4
B) 5
C) 6
D) 7
Answer A

3. Consider the following C program.


#include <stdio.h>
structOutnode {
char x, y, z ;
};
int main () {
structOurnode p = {'1', '0', 'a'+2} ;
structOurnode *q = &p ;
printf ("%c, %c", *((char*)q+1), *((char*)q+2)) ;
return 0 ;
}
The output of this program is
A) 0, c
B) 0, a+2
C) '0', 'a+2'
D) '0', 'c'
Answer A

4. Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun(unsigned long int n) {
unsigned long int i, j, j=0, sum = 0;
for (i = n; i > 1; i = i/2) j++;
for ( ; j > 1; j = j/2) sum++;
return sum;
}
The value returned when we call fun with the input 2^40 is
A) 4
B) 5
C) 6
D) 40
Answer B

5. Consider the following program written in pseudo-code. Assume that x and y are integers.
Count (x, y) {
if (y != 1) {
if (x != 1) {
print("*") ;
Count (x/2, y) ;
}

else {
y=y-1;
Count (1024, y) ;
}
}
}
The number of times that the print statement is executed by the call Count(1024,
1024) is ______.
A) 10230
B) 10231
C) 10232
D) 10233
Answer A

6. Consider the following two functions.


void fun1(int n) { void fun2(int n) {
if(n == 0) return; if(n == 0) return;
printf("%d", n); printf("%d", n);
fun2(n - 2); fun1(++n);
printf("%d", n); printf("%d", n);
}}
The output printed when fun1(5) is called is
A) 53423122233445
B) 53423120112233
C) 53423122132435
D) 53423120213243
Answer A

7. Consider the following function implemented in C:


voidprintxy (int x, int y) {
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d",x,y);
}
The output of invoking printxy(1, 1) is
A) 0, 0
B) 0, 1
C) 1, 0
D) 1, 1
Answer C

8. Consider the C program fragment below which is meant to divide x and y using repeated
subtractions.
The variables x, y, q and r are all unsigned int.
while (r >= y) {
r = r - y;
q = q + 1;
}
Which of the following conditions on the variables x, y, q and r before the
execution of the fragment will ensure
that the loop terminates in a state satisfying the condition x == (y*q + r)?
A) (q == r) && (r == 0)
B) (x> 0) && (r == x) && (y > 0)
C) (q == 0) && (r == x) && (y > 0)
D) (q == 0) && (y > 0)
Answer C

9. Consider the following C program.


#include
int main () {
int m=10;
int n, n1;
n=++m;
n1=m++;
n--;
--n1;
n-=n1;
printf(“%d”, n);
return 0;
}
The output of the program is ______
A) 0
B) 1
C) 2
D) 3
Answer A

10. Consider the following C program.


#include<stdio.h>
#include<string.h>
int main () {
char* c = "GATECSIT2020";
char* p = c;
printf("%d", (int) strlen (c + 2[p] - 6[p] - 1));
return 0;
}
The output of the program is __________.
A) 1
B) 2
C) 4
D) 6
Answer B

11. What is the output of the following C code? Assume that the address of x is 2000 (in
decimal) and an integer requires four bytes of memory.
#include <stdio.h>
int main()
{
unsignedint x[4][3] = {{1, 2, 3}, {4, 5, 6},
{7, 8, 9}, {10, 11, 12}};
printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
A) 2036, 2036, 2036
B) 2012, 4, 2204
C) 2036, 10, 10
D) 2012, 4, 6
Answer A

12. What will be the output of the following pseudocode?


Character var=0x04
var = var | 0x04
Print var
var |= 0x01
Print var
a) 8, 9
b) 4, 5
c) 8, 8
d) 4, 4
Ans:B

13. What will be the output of the code?


main()
{
char str[]="value is =%d";
int a=str[11]='c';
printf(str,a);
}
A) value is ='7'
B) value is = 54
C) Error
D) value is =7
Ans:D

14. What will be the output of the following pseudocode?


Integer x = 10
x &= ~2
Print x
a) 10
b) 8
c) 12
d) 0
Ans:B

15. What will be the output of the following pseudocode?


Integer a[6], p, j, q
Set p = 3
Set a[6] = {3,6,10,12,23,33}
for (each j from 0 to 5)
if((a[j] MOD p) EQUALS 0)
p =a[j] - (p*3)
end if
q = p + a[j] - 3
end for
print q
a) 51
b) 52
c) 53
d) 54
Ans:D

16. What will be the output of the folowing code?


int main()
{
static int var[5];
int count=0;
var[++count]=++count;
for(count=0;count<5;count++)
printf("%d ",var[count]);
return 0;
}
A) 0 0 2 0 0
B)1 2 0 0 0
C) 0 0 2 0 0
D) None of these
Ans:A

17. What will be the output of the given code?


char X[10]={'A'},i;
for(i=0; i<10; i++)
printf("%d ",X[i]);
A) 65 0 0 0 0 0 0 0 0 0 0
B) A \0 \0 \0 \0 \0 \0 \0 \0 \0
C) 65 Garbage ( nine times)
D) None of these
Ans:C

18. What will be the output of the following code?


int main()
{
int val=0;
char str[]="ABC";
val=strcmp(str,"ABC");
printf("%d",val);
return 0;
}
A) 0
B) 1
C) -1
D) None of these
Ans:A

You might also like