Psuedocodes MCQs
Psuedocodes MCQs
Psuedocodes MCQs
main(){
printf("%d",rec(4567));
}
a) 4
b) 12
c) 22
d) 21
Ans:c
}
main()
{
printf("%d",something(4));}
a) 12
b) 24
c) 1
d) 0
Ans:b
if(b==0)
return 0;
if(b==1)
return a;
return a + func(a,b-1);
}
what will be the output of func(3,8) .
a) 11
b) 24
c) 22
d) 21
Ans:b
printf("%d", n%2);
print(n/2);
}
5.int sum(int n) {
if (n==0)
return n;
else
return n + sum(n-1);
}
What will be the output of sum(8).
a)36
b)35
c)34
d)none
Ans:a
7. How many times is the recursive function called, when the following code is executed?
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}
a) 9
b) 10
c) 11
d) 12
Ans:c
void main()
{
static int x = 3;
x++;
if (x <= 5)
{
printf("hi");
main();
}
}
A. Run time error
B. hi
C. infinite hi
D. hihi
Ans:D
void main()
{
static int x;
if (x++ < 2)
main();
}
A. Infinite calls to main
B. Run time error
C. Varies
D. main is called twice
Ans:d
#include<stdio.h>
void fun(int);
int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d,", n);
fun(--n);
}
}
A. 0, 2, 1, 0,
B. 1, 1, 2, 0,
C. 0, 1, 0, 2,
D. 0, 1, 2, 0,
Ans:d
17.Find output of the following
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d\n", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
A. 4, 4
B. 3, 3
C. 6, 6
D. 12, 12
Ans:C
int main()
{
printf("%d", fun(5));
return 0;
}
A) 55
B) 75
C) 15
D) 225
ANS: A
#include<stdio.h>
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf("%d\n", c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}
A. 100
B. 10
C. 1
D. 0
ANS: A
f(int a, int b)
{
int a;
a = 20;
return a;
}
A. Missing parenthesis in return statement
B. The function should be defined as int f(int a, int b)
C. Redeclaration of a
D. None of above
ANS: C
1. Which of the following statement are correct?
(i) The value stored in the CPU register can always be accessed faster than that stored in
memory.
(ii) A register storage class variable will always be stored in a CPU register.
a) Only I is correct
b) Only II is correct
c) Both I & II are correct
d) Both I & II are incorrect
Ans: a)
2. Suppose a variable is declared with register storage class but no register is free then:
a) compilation error
b) data loss
c) it will occupy main memory
d) None of these
Ans: c)
main()
{
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length - i];
printf("%s",p);
}
The output of the program is:
a) gnirts
b) gnirt
c) string
d) no output is printed
Ans: D
Ans: D
1. In the following code what is 'C'?
a. C is a constant.
b. C is a character constant.
c. C is character type.
d. None of the above.
Ans: a
a. 1 Byte
b. 2 Bytes
c. 4 Bytes
d. 8 Bytes
Ans: b
4. What is (void*)0?
#include<stdio.h>
int main()
{
int *ptr, var=5;
ptr = &var;
*ptr += 1;
printf("%d, %d", *ptr, var);
return 0;
}
a. 5, 5
b. 6, 5
c. 5, 6
d. 6, 6
Ans: d
#include<stdio.h>
int main()
{
int var = 5;
void *ptr = &var;
printf("%d\n",(int)*ptr);
return 0;
}
a. 5
b. Runtime Error
c. Compilation Error
d. Undefined behavior
Ans: c
#include<stdio.h>
int main()
{
int a = 15;
void *ptr = &a;
printf("%f\n", *(float *)ptr);
return 0;
}
a. 65624
b. 0.000000
c. 15
d. Error
Ans: b
#include<stdio.h>
int main()
{
int i = 5;
void *ptr = &i;
printf("%d\n", *(int *)ptr);
return 0;
}
a. 5
b. Garbage value
c. Compilation Error
d. None of these.
Ans: a
#include<stdio.h>
int main()
{
char *ptr;
ptr = "A BCD EFGH";
printf("%c",*&*ptr);
return 0;
}
a. A
b. A BCD EFGH
c. Some address will be printed
d. Compilation Error
Ans: a
#include<stdio.h>
void func(int, int);
int main()
{
int i = 5, j = 2;
func (i,j);
printf("%d %d\n", i, j);
return 0;
}
void func (int i, int j)
{
i = i * i;
j = j * j;
}
a. 5, 5
b. 2, 2
c. 25, 4
d. 5, 2
Ans: d
13. What is the output of the following code?
#include<stdio.h>
void func(int *, int *);
int main()
{
int i = 5, j = 2;
func (&i,&j);
printf("%d %d\n", i, j);
return 0;
}
void func (int *i, int *j)
{
*i = *i * *i;
*j = *j * *j;
}
a. 5, 5
b. 2, 2
c. 25, 4
d. 5, 2
Ans: c
#include<stdio.h>
void func(int*);
int main()
{
int i = 5, *ptr = &i;
func(ptr++);
}
void func(int *ptr)
{
printf("%d\n", *ptr);
}
a. 5
b. Garbage Value
c. Compilation Error
d. Segmentation Fault
Ans: a
#include<stdio.h>
int main()
{
int i = 97, *ptr = &i;
func(&ptr);
printf("%d ", *ptr);
return 0;
}
void func(int **ptr)
{
int j = 2;
*ptr = &j;
printf("%d ", **ptr);
}
a. 2 97
b. 2 2
c. Undefined Behaviour
d. Segmentation Fault
Ans: b
#include<stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
a. 6
b. Compile time error
c. 5
d. Junk
Ans: a
17. What is the output of this C code?
#include<stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *ptr = a;
int *r = &ptr;
printf("%d", (**r));
}
a. 1
b. Compile time error
c. Address of a
d. Junk value
Ans: b
#include<stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}
#include<stdio.h>
void main()
{
int a[] = {1,2,9,8,6,3,5,7,8,9};
int *p = a + 1;
int *q = a + 6;
printf("\n%d", q-p);
}
a. 5
b. 9
c. 6
d. 2
Ans: a
9. Which sorting algorithm will take least time when all elements of input array are identical?
Consider typical implementations of sorting algorithms.
(A) Insertion Sort
(B) Heap Sort
(C) Merge Sort
(D) Selection Sort
Answer: a
10. Consider the code given below, which runs insertion sort:
Answer: b
Answer: a
Answer: d
13. Suppose we are sorting an array of eight integers using some quadratic sorting algorithm.
After four iterations of the algorithm’s main loop, the array elements are ordered as shown here:
24578136
A. Insertion sort
B. Selection sort
C. Either of a and b
D. None of the above
Answer: a
Answer: b
#include <stdio.h>
int main()
{
int n = 8;
print(n, 1);
}
(A) 1 7
26
35
44
44
(B) 1 7
26
35
44
(C) 1 7
26
35
(D) 1 2
34
56
78
Answer: b
int *a1[8];
int *(a2[8]);
P. Array of pointers
Q. Pointer to an array
a) a1 is P, a2 is Q
b) a1 is P, a2 is P
c) a1 is Q, a2 is P
d) a1 is Q, a2 is Q
Answer B
#include <stdio.h>
int main()
{
int ary[2][3];
foo(ary);
}
void foo(int *ary[])
{
int i = 10, j = 2, k;
ary[0] = &i;
ary[1] = &j;
*ary[0] = 2;
for (k = 0;k < 2; k++)
printf("%d\n", *ary[k]);
}
a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2
Answer A
#include <stdio.h>
int main()
{
int ary[2][3];
foo(ary);
}
void foo(int (*ary)[3])
{
int i = 10, j = 2, k;
ary[0] = &i;
ary[1] = &j;
for (k = 0;k < 2; k++)
printf("%d\n", *ary[k]);
}
a) Compile time error
b) 10 2
c) Undefined behaviour
d) segmentation fault/code crash
Answer A
#include <stdio.h>
int main()
{
foo(ary);
}
void foo(int **ary)
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = &i;
ary[1] = &j;
printf("%d\n", ary[0][1]);
}
a) 10
b) 2
c) Compile time error
d) Undefined behaviour
Answer D
#include <stdio.h>
int main()
{
int ary[2][3];
ary[][] = {{1, 2, 3}, {4, 5, 6}};
printf("%d\n", ary[1][0]);
}
a) Compile time error
b) 4
c) 1
d) 2
Answer A
1.What will be the output of the program ?
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A.2, 1, 15
B.1, 2, 5
C.3, 2, 15
D.2, 3, 20
Answer C
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
return 0;
}
A. 1, 2, 3, 4, 5,
B. Garbage value, 1, 2, 3, 4,
C. 0, 1, 2, 3, 4,
D. 2, 3, 4, 5, 6,
ANS: B
Answer: d
Answer: d
Answer: c
9. The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending
order, using bubble sort is
(A) 11
(B) 12
(C) 13
(D) 10
Answer: d
10. What is the worst case complexity of binary search using recursion?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: b
11. The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements.
How many iterations will be done to sort the array?
a) 4
b) 2
c) 1
d) 0
Answer: a
Answer: c
#include <stdio.h>
int main()
{
char *a = {"p", "r", "o", "g", "r", "a", "m"};
printf("%s", a);
}
a) program
b) p
c) No output
d) Compile-time error
Answer B
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", *(a[i]));
}
a) segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
Answer A
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0, j = 0;
a[0] = "hey";
for (i = 0;i < 3; i++)
printf("%s\n", a[i]);
}
a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how
d) depends on compiler
Answer C
17. What will be the output of the following C code on a 32-bit system?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a));
}
a) 10
b) 13
c) Run time error
d) 40
Answer D
18. What will be the output of the following C code on a 32-bit system?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a[1]));
}
a) 6
b) 4
c) 5
d) 3
Answer B
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", a[i]);
}
a) hi hello how Segmentation fault
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
Answer D
#include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"};
printf("%s", a[1]);
}
a) hello
b) hello followed by Garbage
c) hellofello
d) Compiler Error
Answer C
1. Assuming, integer is 2 byte, What will be the output of the program?
#include<stdio.h>
int main()
{
printf("%x\n", -2<<2);
return 0;
}
A. ffff
B. 0
C. fff8
D. Error
Ans: C
#include<stdio.h>
int main()
{
int x=12, y=7, z;
z = x!=4 || y == 2;
printf("z=%d\n", z);
return 0;
}
A. z=0
B. z=1
C. z=4
D. z=2
Ans: B
#include<stdio.h>
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf("%d, %d, %d, %d\n", w, x, y, z);
return 0;
}
A. 1, 1, 1, 1
B. 1, 1, 0, 1
C. 1, 0, 0, 1
D. 1, 0, 1, 1
Ans: D
#include<stdio.h>
int reverse(int);
int main()
{
int no=5;
reverse(no);
return 0;
}
int reverse(int no)
{
if(no == 0)
return 0;
else
printf("%d,", no);
reverse (no--);
}
A. Print 5, 4, 3, 2, 1
B. Print 1, 2, 3, 4, 5
C. Print 5, 4, 3, 2, 1, 0
D. Infinite loop
Ans: C///D
#include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
A. AB
B. BC
C. CD
D. No output
Ans: B
#include<stdio.h>
int fun(int);
int main()
{
int i = fun(10);
printf("%d\n", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
A. 9
B. 10
C. 11
D. 8
Ans: A
7. What will be the output of the program?
#include<stdio.h>
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A. Print 10
B. Print 20
C. Print 1
D. Compile error
Ans: D
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s;
printf("%s ,%s", p+1, s+2);
}
a) Run time error
b) hello,llo
c) ello,llo
d) e,l
Ans: C
Ans: B
#include <stdio.h>
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf("%d", p + q);
}
a) 2
b) 3
c) 5
d) Compile time error
Ans: D
12. The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending
order, using bubble sort is
(A) 11
(B) 12
(C) 13
(D) 10
Ans: d
14. The value of j at the end of the execution of the following C program.
int incr (int i)
{
static int count = 0;
count = count + i;
return (count);
}
main ()
{
int i,j;
for (i = 0; i <=4; i++)
j = incr(i);
}
(a) 10
(b) 4
(c) 6
(d) 7
Ans: A
Ans: C
16. In the C language:
a) At most one activation record exists between the current activation record and the activation
record for the main
b) The number of activation records between the current activation record and the activation
record for the main depends on the actual function calling sequence.
c) The visibility of global variables depends on the actual function calling sequence.
d) Recursion requires the activation record for the recursive function to be saved on a different
stack before the recursive function can be called.
Ans: B
main(void)
{
x=5;
P(&x);
print(x);
getchar();
}
The output of this program is:
a) 12 7 6
b) 22 12 11
c) 14 6 6
d) 766
Ans: A
18. Consider the following declaration of a ‘two-dimensional array in C:
char a[100][100];
Assuming that the main memory is byte-addressable and that the array is stored starting from
memory address 0,
and size of char is 1 byte. In row major implementation, the address of a[40][50] is :
a) 4040
b) 4050
c) 5040
d) 5050
Ans: B
Ans: D
main()
{
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
{
p[i] = s[length - i-1];
if(s[length-i-1]== 'a'|| s[length-i-1]== 'e' || s[length-i-1]== 'i'|| s[length-i-1]== 'o'|| s[length-i-1]==
'u')
break;
}
p[i]='\0'
printf("%s",p);
}
The output of the program is:
a) gni
b) gn
c) string
d) no output is printed
Ans: B