DS All Units MCQ
DS All Units MCQ
Answer:d
16) The Average case occurs in the linear search algorithm ……….
A. when the item is somewhere in the middle of the array
B. when the item is not the array at all
C. when the item is the last element in the array
D. Item is the last element in the array or item is not there at all
Answer:a
17) Binary search algorithm cannot be applied to …
A. sorted linked list
B. sorted binary trees
C. sorted linear array
D. pointer array
Answer:a
Answer:a
Answer:c
A. O(n)
B. O(logn)
C. O(n2)
D. O(n logn)
Answer:c
Answer:b
Answer:a
24) …………order is the best possible for array sorting algorithm which sorts n item.
A. O(n logn)
B. O(n2)
C. O(n+logn)
D. O(logn)
Answer:c
25) ……… is rearranging pairs of elements which are out of order, until no such pairs remain.
A. Insertion
B. Exchange
C. Selection
D. Distribution
Answer:b
Answer:a
27) Which of the following sorting algorithm is of divide and conquer type?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Selection sort
Answer:c
28) …….. sorting algorithm is frequently used when n is small where n is total number of elements.
A. Heap
B. Insertion
C. Bubble
D. Quick
Answer:b
29) Which of the following sorting algorithm is of priority queue sorting type?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Selection sort
Answer:d
30) Which of the following is not the required condition for a binary search algorithm?
A. The list must be sorted
B. There should be direct access to the middle element in any sublist
C. There must be a mechanism to delete and/or insert elements in the list.
D. Number values should only be present
Answer:c
Answer:a
32. Which of the following is not a stable sorting algorithm?
a) Insertion sort
b) Selection sort
c) Bubble sort
d) Merge sort
ANSWER: B
33.Which of the following is a stable sorting algorithm?
a) Merge sort
b) Typical in-place quick sort
c) Heap sort
d) Selection sort
34. Which of the following is not an in-place sorting algorithm?
a) Selection sort
b) Heap sort
c) Quick sort
d) Merge sort
ANSWER: D
35.Running merge sort on an array of size n which is already sorted is
a) O(n)
b) O(nlogn)
c) O(n2)
d) None
ANSWER: B
36.The time complexity of a quick sort algorithm which makes use of median, found by
an O(n) algorithm, as pivot element is
a) O(n2)
b) O(nlogn)
c) O(nloglogn)
d) O(n)
ANSWER: B
37.If the given input array is sorted or nearly sorted, which of the following algorithm
gives the best performance?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Merge sort
ANSWER: A
38.Time complexity of bubble sort in best case is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) θ (n(logn) 2)
ANSWER: A
39.Time complexity to sort elements of binary search tree is
a) O(n)
b) O(nlogn)
c) O(n2)
d) O(n2logn)
ANSWER: A
40.Which of the following algorithm design technique is used in the quick sort
algorithm?
a) Dynamic programming
b) Backtracking
c) Divide-and-conquer
d) Greedy method
ANSWER: C
41.Merge sort uses
a) Divide-and-conquer
b) Backtracking
c) Heuristic approach
d) Greedy approach
ANSWER: A
42. For merging two sorted lists of size m and n into sorted list of size m+n, we require
comparisons of
a) O(m)
b) O(n)
c) O(m+n)
d) O(logm + logn)
ANSWER: C
43.What is the worst case complexity of bubble sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
44. Select the appropriate code that performs bubble sort.
a)
}
}
d)
}
}
Answer: b
62. Which of the following sorting algorithms is the fastest?
a) Merge sort
b) Quick sort
c) Insertion sort
d) Shell sort
Answer: b
63. Quick sort follows Divide-and-Conquer strategy.
a) True
b) False
Answer: a
64. What is the worst case time complexity of a quick sort algorithm?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(log N)
Answer: c
65. Which of the following methods is the most effective for picking the pivot element?
a) first element
b) last element
c) median-of-three partitioning
d) random element
Answer: c
66. Find the pivot element from the given input using median-of-three partitioning method.
8, 1, 4, 9, 6, 3, 5, 2, 7, 0.
a) 8
b) 7
c) 9
d) 6
Answer: d
67. Which is the safest method to choose a pivot element?
a) choosing a random element as pivot
b) choosing the first element as pivot
c) choosing the last element as pivot
d) median-of-three partitioning method
Answer: a
68. What is the average running time of a quick sort algorithm?
a) O(N2)
b) O(N)
c) O(N log N)
d) O(log N)
Answer: c
69. Which of the following sorting algorithms is used along with quick sort to sort the sub
arrays?
a) Merge sort
b) Shell sort
c) Insertion sort
d) Bubble sort
Answer: c
70. Quick sort uses join operation rather than merge operation.
a) true
b) false
Answer: a
71. How many sub arrays does the quick sort algorithm divide the entire array into?
a) one
b) two
c) three
d) four
Answer: b
72. Which of the following is not an in-place sorting algorithm?
A. Selection sort
B. Heap sort
C. Quick sort
D. Merge sort
Ans : D
73. What is the advantage of bubble sort over other sorting techniques?
A. It is faster
B. Consumes less memory
C. Detects whether the input is already sorted
D. All of the mentioned
Ans : C
74. The complexity of sorting algorithm measures the …… as a function of the number n of
items to be sorter.
A. average time
B. running time
C. average-case complexity
D. case-complexity
Ans : B
75. Suppose we are sorting an array of eight integers using quicksort, and we have just
finished the first partitioning with the array looking like this:
2 5 1 7 9 12 11 10
Which statement is correct?
Answer: a
84. Which of the following is a disadvantage of linear search?
a) Requires more space
b) Greater time complexities compared to other searching algorithms
c) Not easy to understand
d) Not easy to implement
Answer: b
85. What is the advantage of recursive approach than an iterative approach?
a) Consumes less memory
b) Less code and easy to implement
c) Consumes more memory
d) More code has to be written
Answer: b
86. Given an input arr = {2,5,7,99,899}; key = 899; What is the level of recursion?
a) 5
b) 2
c) 3
d) 4
Answer: c
87. Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid
values(corresponding array elements) in the first and second levels of recursion?
a) 90 and 99
b) 90 and 94
c) 89 and 99
d) 89 and 94
Answer: a
88. 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
89. What is the average case time complexity of binary search using recursion?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: b
90. Which of the following is not an application of binary search?
a) To find the lower/upper bound in an ordered sequence
b) Union of intervals
c) Debugging
d) To search in unordered list
Answer: d
91. Binary Search can be categorized into which of the following?
a) Brute Force technique
b) Divide and conquer
c) Greedy algorithm
d) Dynamic programming
Answer: b
92. Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done until the
element is found?
a) 1
b) 3
c) 4
d) 2
Answer: d
93. Given an array arr = {45,77,89,90,94,99,100} and key = 100; What are the mid
values(corresponding array elements) generated in the first and second iterations?
a) 90 and 99
b) 90 and 100
c) 89 and 94
d) 94 and 99
Answer: a
94 . What is the time complexity of binary search with iteration?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: b
95. What is the worst case runtime of linear search(recursive) algorithm?
a) O(n)
b) O(logn)
c) O(n2)
d) O(nx)
Answer: a
96. Linear search(recursive) algorithm used in _____________
a) When the size of the dataset is low
b) When the size of the dataset is large
c) When the dataset is unordered
d) Never used
Answer: a
97. The array is as follows: 1,2,3,6,8,10. At what time the element 6 is found? (By using
linear search(recursive) algorithm)
a) 4th call
b) 3rd call
c) 6th call
d) 5th call
Answer: a
98. The array is as follows: 1,2,3,6,8,10. Given that the number 17 is to be searched. At
which call it tells that there’s no such element? (By using linear search(recursive) algorithm)
a) 7th call
b) 9th call
c) 17th call
d) The function calls itself infinite number of times
Answer: a
99. What is the best case runtime of linear search(recursive) algorithm on an ordered set of
elements?
a) O(1)
b) O(n)
c) O(logn)
d) O(nx)
Answer: a
100. Can linear search recursive algorithm and binary search recursive algorithm be
performed on an unordered list?
a) Binary search can’t be used
b) Linear search can’t be used
c) Both cannot be used
d) Both can be used
Answer: a
100 MCQ on Unit 4
i=i+pow(2,currentlevel);
currentlevel=currentlevel+2;
j=1;
b)
i=i+pow(2,currentlevel);
currentlevel=currentlevel+2;
j=0;
c)
i=i-pow(2,currentlevel);
currentlevel=currentlevel+2;
j=1;
d)
i=i+pow(2,currentlevel);
currentlevel=currentlevel+1;
j=1;
Answer: a
8. Consider a situation of writing a binary tree into a file with memory storage efficiency in
mind, is array representation of tree is good?
a) yes because we are overcoming the need of pointers and so space efficiency
b) yes because array values are indexable
c) No it is not efficient in case of sparse trees and remaning cases it is fine
d) No linked list representation of tree is only fine
Answer: c
9. Can a tree stored in an array using either one of inorder or post order or pre order traversals
be again reformed?
a) Yes just traverse through the array and form the tree
b) No we need one more traversal to form a tree
c) No in case of sparse trees
d) Yes by using both inorder and array elements
Answer: b
10. Advantages of linked list representation of binary trees over arrays?
a) dynamic size
b) ease of insertion/deletion
c) ease in randomly accessing a node
d) both dynamic size and ease in insertion/deletion
Answer: d
11. Disadvantages of linked list representation of binary trees over arrays?
a) Randomly accessing is not possible
b) Extra memory for a pointer is needed with every element in the list
c) Difficulty in deletion
d) Random access is not possible and extra memory with every element
Answer: d
12. Which of the following traversing algorithm is not used to traverse in a tree?
a) Post order
b) Pre order
c) Post order
d) Randomized
Answer: d
13. Level order traversal of a tree is formed with the help of
a) breadth first search
b) depth first search
c) dijkstra’s algorithm
d) prims algorithm
Answer: a
14. Identify the reason which doesn’t play a key role to use threaded binary trees?
a) The storage required by stack and queue is more
b) The pointers in most of nodes of a binary tree are NULL
c) It is Difficult to find a successor node
d) They occupy less size
Answer: d
15. What may be the psuedo code for finding the size of a tree?
a) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)
b) find_size(root_node–>left_node) + find_size(root_node–>right_node)
c) find_size(root_node–>right_node) – 1
d) find_size(root_node–>left_node + 1
Answer: a
16. What is missing in this logic of finding a path in the tree for a given sum (i.e checking
whether there will be a path from roots to leaf nodes with given sum)?
Answer: a
17. What must be the missing logic below so as to print mirror of a tree as below as an
example?
if(rootnode):
mirror(rootnode-->left)
mirror(rootnode-->right)
//missing
end
a) swapping of left and right nodes is missing
b) swapping of left with root nodes is missing
c) swapping of right with root nodes is missing
d) nothing is missing
Answer: a
18. What is the code below trying to print?
Answer: c
19. What is the maximum number of children that a binary tree node can have?
a) 0
b) 1
c) 2
d) 3
Answer: c
20. The following given tree is an example for?
a) Binary tree
b) Binary search tree
c) Fibonacci tree
d) AVL tree
Answer: a
21. A binary tree is a rooted tree but not an ordered tree.
a) true
b) false
Answer: b
22. How many common operations are performed in a binary tree?
a) 1
b) 2
c) 3
d) 4
Answer: c
23. What is the traversal strategy used in the binary tree?
a) depth-first traversal
b) breadth-first traversal
c) random traversal
d) Priority traversal
Answer: b
24. How many types of insertion are performed in a binary tree?
a) 1
b) 2
c) 3
d) 4
Answer: b
25. What operation does the following diagram depict?
a)
b)
c)
d)
Answer: d
33. For the tree below, write the pre-order traversal.
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer: a
34. For the tree below, write the post-order traversal.
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer: c
35. Select the code snippet which performs pre-order traversal.
a)
Answer: b
37. Select the code snippet that performs pre-order traversal iteratively.
a)
public void preOrder(Tree root)
{
if (root == null) return;
Stack<Tree> stk = new Stack<Tree>();
st.add(root);
while (!stk.empty())
{
Tree node = stk.pop();
System.out.print(node.data + " ");
if (node.left != null) stk.push(node.left);
if (node.right != null) stk.push(node.right);
}
}
b)
a) P Q R S T U V W X
b) W R S Q P V T U X
c) S W T Q X U V R P
d) S T W U X V Q R P
Answer: c
53. For the tree below, write the in-order traversal.
a) 6, 2, 5, 7, 11, 2, 5, 9, 4
b) 6, 5, 2, 11, 7, 4, 9, 5, 2
c) 2, 7, 2, 6, 5, 11, 5, 9, 4
d) 2, 7, 6, 5, 11, 2, 9, 5, 4
Answer: a
54. For the tree below, write the level-order traversal.
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 11, 9, 6, 5, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer: b
55. What is the space complexity of the in-order traversal in the recursive fashion? (d is the
tree depth and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
Answer: d
56. What is the time complexity of level order traversal?
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
Answer: b
57. Which of the following graph traversals closely imitates level order traversal of a binary
tree?
a) Depth First Search
b) Breadth First Search
c) Depth & Breadth First Search
d) Binary Search
Answer: b
58. In a binary search tree, which of the following traversals would print the numbers in the
ascending order?
a) Level-order traversal
b) Pre-order traversal
c) Post-order traversal
d) In-order traversal
Answer: d
59. The number of edges from the root to the node is called __________ of the tree.
a) Height
b) Depth
c) Length
d) Width
Answer: b
60. The number of edges from the node to the deepest leaf is called _________ of the tree.
a) Height
b) Depth
c) Length
d) Width
Answer: a
61. What is a full binary tree?
a) Each node has exactly zero or two children
b) Each node has exactly two children
c) All the leaves are at the same level
d) Each node has exactly one or two children
Answer: a
62. What is a complete binary tree?
a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the bottom level,
which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the bottom level,
which is filled from left to right
d) A tree In which all nodes have degree 2
Answer: c
63. What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)
Answer: d
64. Which of the following is not an advantage of trees?
a) Hierarchical structure
b) Faster search
c) Router algorithms
d) Undo/Redo operations in a notepad
Answer: d
65. In a full binary tree if number of internal nodes is I, then number of leaves L are?
a) L = 2*I
b) L = I + 1
c) L = I – 1
d) L = 2*I – 1
Answer: b
66. Which of the following is incorrect with respect to binary trees?
a) Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k
b) Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes
c) Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log (N + 1))
d) Let T be a binary tree with N nodes. Then the number of levels is at least floor(log (N + 1))
Answer: d
67. Construct a binary tree by using postorder and inorder sequences given below.
Inorder: N, M, P, O, Q
Postorder: N, P, Q, O, M
a)
b)
c)
d)
Answer: d
68. Construct a binary search tree by using postorder sequence given below.
Postorder: 2, 4, 3, 7, 9, 8, 5.
a)
b)
c)
d)
Answer: b
69. Construct a binary tree using inorder and level order traversal given below.
Inorder Traversal: 3, 4, 2, 1, 5, 8, 9
Level Order Traversal: 1, 4, 5, 9, 8, 2, 3
a)
b)
c)
d)
Answer: a
70. Which of the following is false about a binary search tree?
a) The left child is always lesser than its parent
b) The right child is always greater than its parent
c) The left and right sub-trees should also be binary search trees
d) In order sequence gives decreasing order of elements
Answer: d
71. How to search for a key in a binary search tree?
a)
Answer: c
75. What are the worst case and average case complexities of a binary search tree?
a) O(n), O(n)
b) O(logn), O(logn)
c) O(logn), O(n)
d) O(n), O(logn)
Answer: d
76. Construct a binary search tree with the below information.
The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12.
a)
b)
c)
d)
Answer: c
77. Which of the following statements for a simple graph is correct?
a) Every path is a trail
b) Every trail is a path
c) Every trail is a path as well as every path is a trail
d) Path and trail have no relation
Answer: a
78. n the given graph identify the cut vertices.
a) B and E
b) C and D
c) A and E
d) C and B
Answer: d
79. For the given graph(G), which of the following statements is true?
a) G is a complete graph
b) G is not a connected graph
c) The vertex connectivity of the graph is 2
d) The edge connectivity of the graph is 1
Answer: c
80. What is the number of edges present in a complete graph having n vertices?
a) (n*(n+1))/2
b) (n*(n-1))/2
c) n
d) Information given is insufficient
Answer: b
81. The given Graph is regular.
a) True
b) False
Answer: a
82. In a simple graph, the number of edges is equal to twice the sum of the degrees of the
vertices.
a) True
b) False
Answer: b
83. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
a) 15
b) 3
c) 1
d) 11
Answer: b
84. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________
a) (n*n-n-2*m)/2
b) (n*n+n+2*m)/2
c) (n*n-n-2*m)/2
d) (n*n-n+2*m)/2
Answer: a
85. Which of the following properties does a simple graph not hold?
a) Must be connected
b) Must be unweighted
c) Must have no loops or multiple edges
d) Must have no multiple edges
Answer: a
86. What is the maximum number of edges in a bipartite graph having 10 vertices?
a) 24
b) 21
c) 25
d) 16
Answer: c
87. Which of the following is true?
a) A graph may contain no edges and many vertices
b) A graph may contain many edges and no vertices
c) A graph may contain no edges and no vertices
d) A graph may contain no vertices and many edges
Answer: b
88. For a given graph G having v vertices and e edges which is connected and has no cycles,
which of the following statements is true?
a) v=e
b) v = e+1
c) v + 1 = e
d) v = e-1
Answer: b
89. For which of the following combinations of the degrees of vertices would the connected
graph be eulerian?
a) 1,2,3
b) 2,3,4
c) 2,4,5
d) 1,3,5
90. A graph with all vertices having equal degree is known as a __________
a) Multi Graph
b) Regular Graph
c) Simple Graph
d) Complete Graph
Answer: b
91. Which of the following ways can be used to represent a graph?
a) Adjacency List and Adjacency Matrix
b) Incidence Matrix
c) Adjacency List, Adjacency Matrix as well as Incidence Matrix
d) No way to represent
Answer: c
92. The number of elements in the adjacency matrix of a graph having 7 vertices is
__________
a) 7
b) 14
c) 36
d) 49
Answer: d
93. What would be the number of zeros in the adjacency matrix of the given graph?
a) 10
b) 6
c) 16
d) 0
Answer: b
94. The time complexity to calculate the number of edges in a graph whose information in
stored in form of an adjacency matrix is ____________
a) O(V)
b) O(E2)
c) O(E)
d) O(V2)
Answer: d
95. For the adjacency matrix of a directed graph the row sum is the _________ degree and
the column sum is the ________ degree.
a) in, out
b) out, in
c) in, total
d) total, out
96. Space complexity for an adjacency list of an undirected graph having large values of V
(vertices) and E (edges) is ___________
a) O(E)
b) O(V*V)
c) O(E+V)
d) O(V)
Answer: c
97. Time complexity to find if there is an edge between 2 particular vertices is _________
a) O(V)
b) O(E)
c) O(1)
d) O(V+E)
Answer: a
98. Space complexity for an adjacency list of an undirected graph having large values of V
(vertices) and E (edges) is __________
a) O(V)
b) O(E*E)
c) O(E)
d) O(E+V)
Answer: c
99. A graph having an edge from each vertex to every other vertex is called a ___________
a) Tightly Connected
b) Strongly Connected
c) Weakly Connected
d) Loosely Connected
Answer: a
100. What is the number of unlabeled simple directed graph that can be made with 1 or 2
vertices?
a) 2
b) 4
c) 5
d) 9
Answer: b
100 MCQ – UNIT 3
Arrays and its representations – Stacks and Queues – Linked lists – Linked list-based implementation
of Stacks and Queues – Evaluation of Expressions – Linked list based polynomial addition.
Answer: b
2. How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Answer: c
3. How do you instantiate an array in Java?
a) int arr[] = new int(3);
b) int arr[];
c) int arr[] = new int[3];
d) int arr() = new int(3);
Answer: c
4. Which of the following is a correct way to declare a multidimensional array in Java?
a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;
Answer: c
5. What is the output of the following piece of code?
a) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2
Answer: a
6. What is the output of the following piece of code?
Answer: c
7. When does the ArrayIndexOutOfBoundsException occur?
a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all
Answer: b
8. Which of the following concepts make extensive use of arrays?
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
Answer: d
9. What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
Answer: d
10. What are the disadvantages of arrays?
a) Data structure like queue or stack cannot be implemented
b) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed
Answer: b
11.Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Answer: d
12. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Answer: a
13. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
Answer: a
14. 1. Process of inserting an element in stack is called ____________
a) Create
b) Push
c) Evaluation
d) Pop
Answer: b
15. Process of removing an element from stack is called __________
a) Create
b) Push
c) Evaluation
d) Pop
Answer: d
16. In a stack, if a user tries to remove an element from empty stack it is called
_________
a) Underflow
b) Empty collection
c) Overflow
d) Garbage Collection
Answer: a
17. Pushing an element into stack already having five elements and stack size of 5, then
stack becomes
a) Overflow
b) Crash
c) Underflow
d) User flow
Answer: a
18. Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one
Answer: d
19. Which of the following is not the application of stack?
a) A parentheses balancing program
b) Tracking of local variables at run time
c) Compiler Syntax Analyzer
d) Data Transfer between two asynchronous process
Answer: d
20. Consider the usual algorithm for determining whether a sequence of parentheses is
balanced.
The maximum number of parentheses that appear on the stack AT ANY ONE TIME
when the algorithm analyzes: (()(())(())) are:
a) 1
b) 2
c) 3
d) 4 or more
Answer: c
21. Consider the usual algorithm for determining whether a sequence of parentheses is
balanced.
Suppose that you run the algorithm on a sequence that contains 2 left parentheses and
3 right parentheses (in some order).
The maximum number of parentheses that appear on the stack AT ANY ONE TIME
during the computation?
a) 1
b) 2
c) 3
d) 4 or more
Answer: b
22. What is the value of the postfix expression 6 3 2 4 + – *?
a) 1
b) 40
c) 74
d) -18
Answer: d
23. Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual
stack algorithm to convert the expression from infix to postfix notation.
The maximum number of symbols that will appear on the stack AT ONE TIME during the
conversion of this expression?
a) 1
b) 2
c) 3
d) 4
Answer: d
24. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
a) AB+ CD*E – FG /**
b) AB + CD* E – F **G /
c) AB + CD* E – *F *G /
d) AB + CDE * – * F *G /
Answer: c
25. The data structure required to check whether an expression contains balanced
parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree
Answer: a
26. What data structure would you mostly likely see in a non recursive implementation
of a recursive algorithm?
a) Linked List
b) Stack
c) Queue
d) Tree
Answer: b
27. The process of accessing data stored in a serial access memory is similar to
manipulating data on a ________
a) Heap
b) Binary Tree
c) Array
d) Stack
Answer: d
28. The postfix form of A*B+C/D is?
a) *AB/CD+
b) AB*CD/+
c) A*BC+/D
d) ABCD+/*
Answer: b
29. Which data structure is needed to convert infix notation to postfix notation?
a) Branch
b) Tree
c) Queue
d) Stack
Answer: d
30. The prefix form of A-B/ (C * D ^ E) is?
a) -/*^ACBDE
b) -ABCD*^DE
c) -A/B*C^DE
d) -A/BC*^DE
Answer: c
31. What is the result of the following operation?
Top (Push (S, X))
a) X
b) X+S
c) S
d) XS
Answer: a
32. The prefix form of an infix expression (p + q) – (r * t) is?
a) + pq – *rt
b) – +pqr * t
c) – +pq * rt
d) – + * pqrt
Answer: c
33. Which data structure is used for implementing recursion?
a) Queue
b) Stack
c) Array
d) List
Answer: b
34. The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a) 600
b) 350
c) 650
d) 588
Answer: b
35. Convert the following infix expressions into its equivalent postfix expressions
(A + B ⋀D)/(E – F)+G
a) (A B D ⋀ + E F – / G +)
b) (A B D +⋀ E F – / G +)
c) (A B D ⋀ + E F/- G +)
d) (A B D E F + ⋀ / – G +)
Answer: a
36. Convert the following Infix expression to Postfix form using a stack
x + y * z + (p * q + r) * s, Follow usual precedence rule and assume that the expression
is legal.
a) xyz*+pq*r+s*+
b) xyz*+pq*r+s+*
c) xyz+*pq*r+s*+
d) xyzp+**qr+s*+
Answer: a
37. Which of the following statement(s) about stack data structure is/are NOT correct?
a) Linked List are used for implementing Stacks
b) Top of the Stack always contain the new node
c) Stack is the FIFO data structure
d) Null link is present in the last node at the bottom of the stack
Answer: c
38. Consider the following operation performed on a stack of size 5.
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
Pop();
Push(5);
After the completion of all operation, the number of elements present in stack are
a) 1
b) 2
c) 3
d) 4
Answer: a
39. Which of the following is not an inherent application of stack?
a) Reversing a string
b) Evaluation of postfix expression
c) Implementation of recursion
d) Job scheduling
Answer: d
40. The type of expression in which operator succeeds its operands is?
a) Infix Expression
b) Prefix Expression
c) Postfix Expression
d) Both Prefix and Postfix Expressions
Answer: c
41. Assume that the operators +,-, X are left associative and ^ is right associative.
The order of precedence (from highest to lowest) is ^, X, +, -. The postfix expression for
the infix expression a + b X c – d ^ e ^ f is
a) abc X+ def ^^ –
b) abc X+ de^f^ –
c) ab+c Xd – e ^f^
d) -+aXbc^ ^def
Answer: b
42. If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a
time, what is the order of removal?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: b
43. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
44. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
Answer: c
45. A queue follows __________
a) FIFO (First In First Out) principle
b) LIFO (Last In First Out) principle
c) Ordered array
d) Linear tree
Answer: a
46. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
47. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a
time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: a
48. A data structure in which elements can be inserted or deleted at/from both the ends
but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
49. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
50. Queues serve major role in ______________
a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) Simulation of heap sort
Answer: c
51. Which of the following is not the type of queue?
a) Ordinary queue
b) Single ended queue
c) Circular queue
d) Priority queue
Answer: b
52. A linear collection of data elements where the linear node is given by means of
pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer: a
53. Consider an implementation of unsorted singly linked list. Suppose it has its
representation with a head pointer only.
Given the representation, which of the following operation can be implemented in O(1)
time?
i) Insertion at the front of the linked list
ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list
a) I and II
b) I and III
c) I, II and III
d) I, II and IV
Answer: b
54. In linked list each node contain minimum of two fields. One field is data field to store
the data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
Answer: c
55. What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
Answer: c
56. What would be the asymptotic time complexity to insert an element at the front of the
linked list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
57. What would be the asymptotic time complexity to find an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n4)
Answer: b
58. What would be the asymptotic time complexity to insert an element at the second
position in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
59. The concatenation of two list can performed in O(1) time. Which of the following
variation of linked list can be used?
a) Singly linked list
b) Doubly linked list
c) Circular doubly linked list
d) Array implementation of list
Answer: c
60. Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
Answer: a
61. Which of the following is not a disadvantage to the usage of array?
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size
c) Insertion based on position
d) Accessing elements at specified positions
Answer: d
62. What is the time complexity of inserting at the end in dynamic arrays?
a) O(1)
b) O(n)
c) O(logn)
d) Either O(1) or O(n)
Answer: d
63. What is the time complexity to count the number of elements in the linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
Answer: b
64. Which of the following performs deletion of the last element in the list? Given below
is the Node class.
class Node
{
protected Node next;
protected Object ele;
Node(Object e,Node n)
{
ele = e;
next = n;
}
public void setNext(Node n)
{
next = n;
}
public void setEle(Object e)
{
ele = e;
}
public Node getNext()
{
return next;
}
public Object getEle()
{
return ele;
}
}
class SLL
{
Node head;
int size;
SLL()
{
size = 0;
}
}
a)
Answer: c
66. What is the space complexity for deleting a linked list?
a) O(1)
b) O(n)
c) Either O(1) or O(n)
d) O(logn)
Answer: a
67. How would you delete a node in the singly linked list? The position to be deleted is
given.
a)
b)
c)
d)
Answer: a
71. What is the functionality of the following piece of code?
public int function(int data)
{
Node temp = head;
int var = 0;
while(temp != null)
{
if(temp.getData() == data)
{
return var;
}
var = var+1;
temp = temp.getNext();
}
return Integer.MIN_VALUE;
}
a) Find and delete a given element in the list
b) Find and return the given element in the list
c) Find and return the position of the given element in the list
d) Find and insert a new element in the list
Answer: c
72. Which of the following is false about a doubly linked list?
a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list
Answer: d
73. iven the Node class implementation, select one of the following that correctly inserts
a node at the tail of the list.
Answer: c
80. What is the functionality of the following piece of code?
Answer: b
81.Consider the following doubly linked list: head-1-2-3-4-5-tail
What will be the list after performing the given sequence of operations?
82. What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
d) Head node is known in circular linked list
Answer: c
83. What is the time complexity of searching for an element in a circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) O(n2)
Answer: a
84. Which of the following application makes use of a circular linked list?
a) Undo operation in a text editor
b) Recursive function calls
c) Allocating CPU to resources
d) Implement Hash Tables
Answer: c
85. Which of the following real world scenarios would you associate with a stack data
structure?
a) piling up of chairs one above the other
b) people standing in a line to be serviced at a counter
c) offer services based on the priority of the customer
d) tatkal Ticket Booking in IRCTC
Answer: a
86. hat does the following function check for? (all necessary headers to be included and
function is called from main)
#define MAX 10
Answer: c
87. What does ‘stack underflow’ refer to?
a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception
Answer: c
88. What is the time complexity of pop() operation when the stack is implemented using
an array?
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
Answer: a
89. Which of the following array position will be occupied by a new element being
pushed for a stack of size N elements(capacity of stack > N).
a) S[N-1]
b) S[N]
c) S[1]
d) S[0]
Answer: b
90. What happens when you pop from an empty stack while implementing using the
Stack ADT in Java?
a) Undefined error
b) Compiler displays a warning
c) EmptyStackException is thrown
d) NoStackException is thrown
Answer: c
91.What is the best case time complexity of deleting a node in Singly Linked list?
a) O (n)
b) O (n2)
c) O (nlogn)
d) O (1)
Answer: d
92. Which of the following statements are not correct with respect to Singly Linked
List(SLL) and Doubly Linked List(DLL)?
a) Complexity of Insertion and Deletion at known position is O(n) in SLL and O(1) in DLL
b) SLL uses lesser memory per node than DLL
c) DLL has more searching power than SLL
d) Number of node fields in SLL is more than DLL
Answer: d
93. What does the following function do?
public Object some_func()throws emptyStackException
{
if(isEmpty())
throw new emptyStackException("underflow");
return first.getEle();
}
a) pop
b) delete the top-of-the-stack element
c) retrieve the top-of-the-stack element
d) push operation
Answer: c
Answer: b
Answer: b
96. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack
Answer: d
Answer: c
98. In linked list implementation of queue, if only front pointer is maintained, which of
the following operation take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
d) Both Insertion and To empty a queue
Answer: d
99. In linked list implementation of a queue, where does a new element be inserted?
a) At the head of link list
b) At the centre position in the link list
c) At the tail of the link list
d) At any position in the linked list
Answer: c
100. In linked list implementation of a queue, front and rear pointers are tracked. Which
of these pointers will change during an insertion into a NONEMPTY queue?
a) Only front pointer
b) Only rear pointer
c) Both front and rear pointer
d) No pointer will be changed
Answer: b
100 MCQ - UNIT 2
1.What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. printf("1 ");
6. foo();
7. }
8. void foo()
9. {
10. printf("2 ");
11. }
a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler
Answer: a
2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo(), f();
5. f();
6. }
7. void foo()
8. {
9. printf("2 ");
10. }
11. void f()
12. {
13. printf("1 ");
14. foo();
15. }
a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main
Answer: b
3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. void f()
6. {
7. foo();
8. }
9. f();
10. }
11. void foo()
12. {
13. printf("2 ");
14. }
a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler
Answer: d
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo();
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
Answer: b
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo(1);
7. return 0;
8. }
9. void foo(int i)
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: a
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: b
1. #include <stdio.h>
2. void m()
3. {
4. printf("hi");
5. }
6. void main()
7. {
8. m();
9. }
a) hi
b) Run time error
c) Nothing
d) Varies
Answer: a
1. #include <stdio.h>
2. void m();
3. void n()
4. {
5. m();
6. }
7. void main()
8. {
9. void m()
10. {
11. printf("hi");
12. }
13. }
a) hi
b) Compile time error
c) Nothing
d) Varies
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. void m()
6. {
7. printf("hi");
8. }
9. }
a) hi
b) Compile time error
c) Nothing
d) Varies
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. }
6. void m()
7. {
8. printf("hi");
9. m();
10. }
a) Compile time error
b) hi
c) Infinite hi
d) Nothing
1. #include <stdio.h>
2. void main()
3. {
4. static int x = 3;
5. x++;
6. if (x <= 5)
7. {
8. printf("hi");
9. main();
10. }
11. }
a) Run time error
b) hi
c) Infinite hi
d) hi hi
Answer: d
Answer: d
int sum(a, b)
return (a + b);
d) none of the mentioned
Answer: b
15. Can we use a function as a parameter of another function? [Eg: void wow(int func())].
a) Yes, and we can use the function value conveniently
b) Yes, but we call the function again to get the value, not as convenient as in using variable
c) No, C does not support it
d) This case is compiler dependent
Answer: c
16. The value obtained in the function is given back to main by using ________ keyword.
a) return
b) static
c) new
d) volatile
Answer: a
Answer: c
18. Which of the following function declaration is illegal?
a)
double func();
int main(){}
double func(){}
b)
double func(){};
int main(){}
c)
int main()
{
double func();
}
double func(){//statements}
d) None of the mentioned
Answer: d
19. What will be the output of the following C code having void return-type function?
1. #include <stdio.h>
2. void foo()
3. {
4. return 1;
5. }
6. void main()
7. {
8. int x = 0;
9. x = foo();
10. printf("%d", x);
11. }
a) 1
b) 0
c) Runtime error
d) Compile time error
Answer: d
20. What will be the data type returned for the following C function?
1. #include <stdio.h>
2. int func()
3. {
4. return (double)(char)5.0;
5. }
a) char
b) int
c) double
d) multiple type-casting in return is illegal
Answer: b
int func(int);
double func(int);
int func(float);
a) A function with same name cannot have different signatures
b) A function with same name cannot have different return types
c) A function with same name cannot have different number of parameters
d) All of the mentioned
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int k = m();
5. printf("%d", k);
6. }
7. void m()
8. {
9. printf("hello");
10. }
a) hello 5
b) Error
c) Nothing
d) Junk value
Answer: a
1. #include <stdio.h>
2. int *m()
3. {
4. int *p = 5;
5. return p;
6. }
7. void main()
8. {
9. int *k = m();
10. printf("%d", k);
11. }
a) 5
b) Junk value
c) 0
d) Error
Answer: a
1. #include <stdio.h>
2. int *m();
3. void main()
4. {
5. int *k = m();
6. printf("hello ");
7. printf("%d", k[0]);
8. }
9. int *m()
10. {
11. int a[2] = {5, 8};
12. return a;
13. }
a) hello 5 8
b) hello 5
c) hello followed by garbage value
d) Compilation error
Answer: c
1. #include <stdio.h>
2. int *m();
3. void main()
4. {
5. int k = m();
6. printf("%d", k);
7. }
8. int *m()
9. {
10. int a[2] = {5, 8};
11. return a;
12. }
a) 5
b) 8
c) Nothing
d) Varies
Answer: d
1. #include <stdio.h>
2. void m(int k)
3. {
4. printf("hi");
5. }
6. void m(double k)
7. {
8. printf("hello");
9. }
10. void main()
11. {
12. m(3);
13. }
a) hi
b) hello
c) Compile time error
d) Nothing
Answer: c
27. What is the default return type if it is not specified in function definition?
a) void
b) int
c) double
d) short int
Answer: b
1. #include <stdio.h>
2. int foo();
3. int main()
4. {
5. int i = foo();
6. }
7. foo()
8. {
9. printf("2 ");
10. return 2;
11. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: a
1. #include <stdio.h>
2. double foo();
3. int main()
4. {
5. foo();
6. return 0;
7. }
8. foo()
9. {
10. printf("2 ");
11. return 2;
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: b
Answer: a
Answer: a
1. #include <stdio.h>
2. enum m{JAN, FEB, MAR};
3. enum m foo();
4. int main()
5. {
6. enum m i = foo();
7. printf("%d\n", i);
8. }
9. int foo()
10. {
11. return JAN;
12. }
a) Compile time error
b) 0
c) Depends on the compiler
d) Depends on the standard
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. printf("%d", x);
6. }
7. int x;
8. void m()
9. {
10. x = 4;
11. }
a) 4
b) Compile time error
c) 0
d) Undefined
Answer: b
Answer: c
1. #include <stdio.h>
2. int x = 5;
3. void main()
4. {
5. int x = 3;
6. printf("%d", x);
7. {
8. x = 4;
9. }
10. printf("%d", x);
11. }
a) Run time error
b) 3 3
c) 3 5
d) 3 4
Answer: d
1. #include <stdio.h>
2. int x = 5;
3. void main()
4. {
5. int x = 3;
6. printf("%d", x);
7. {
8. int x = 4;
9. }
10. printf("%d", x);
11. }
a) 3 3
b) 3 4
c) 3 5
d) Run time error
Answer: a
Answer: b
Answer: b
1. #include <stdio.h>
2. int func (int a)
3. {
4. int b;
5. return b;
6. }
7. int main()
8. {
9. int c;
10. func (c);
11. }
12. int d;
a) a
b) b
c) c
d) d
Answer: d
Answer: d
1. #include <stdio.h>
2. double var = 8;
3. int main()
4. {
5. int var = 5;
6. printf("%d", var);
7. }
a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. char *p = NULL;
5. char *q = 0;
6. if (p)
7. printf(" p ");
8. else
9. printf("nullp");
10. if (q)
11. printf("q\n");
12. else
13. printf(" nullq\n");
14. }
a) nullp nullq
b) Depends on the compiler
c) x nullq where x can be p or nullp depending on the value of NULL
d) p q
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. void *p = &i;
6. printf("%d\n", (int)*p);
7. return 0;
8. }
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviou
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. void *p = &i;
6. printf("%f\n", *(float*)p);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 10
d) 0.000000
Answer: d
1. #include <stdio.h>
2. int *f();
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);
7. }
8. int *f()
9. {
10. int *j = (int*)malloc(sizeof(int));
11. *j = 10;
12. return j;
13. }
a) 10
b) Compile time error
c) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour
Answer: a
1. #include <stdio.h>
2. int *f();
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);
7. }
8. int *f()
9. {
10. int j = 10;
11. return &j;
12. }
a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behaviour
Answer: a
int *ptr, p;
Answer: a
48. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int *ptr, a = 10;
5. ptr = &a;
6. *ptr += 1;
7. printf("%d,%d/n", *ptr, a);
8. }
a) 10,10
b) 10,11
c) 11,10
d) 11,11
Answer: d
Answer: a
50. Property which allows to produce different executable for different platforms in C is
called?
a) File inclusion
b) Selective inclusion
c) Conditional compilation
d) Recursive macros
Answer: c
Answer: a
52. C preprocessors can have compiler specific features.
a) True
b) False
c) Depends on the standard
d) Depends on the platform
Answer: a
1. #include <stdio.h>
2. #define foo(m, n) m * n = 10
3. int main()
4. {
5. printf("in main\n");
6. }
a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
Answer: a
Answer: a
55. Preprocessor feature that supply line numbers and filenames to compiler is called?
a) Selective inclusion
b) macro substitution
c) Concatenation
d) Line control
Answer: d
56. #include <somefile.h> are _______ files and #include “somefile.h” ________ files.
a) Library, Library
b) Library, user-created header
c) User-created header, library
d) They can include all types of file
Answer: d
57. What is a preprocessor?
a) That processes its input data to produce output that is used as input to another program
b) That is nothing but a loader
c) That links various source files
d) All of the mentioned
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. printf("%p\t%p", p, a);
7. }
a) Same address is printed
b) Different address is printed
c) Compile time error
d) Nothing
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s;
6. printf("%p\t%p", p, s);
7. }
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. char *s= "hello";
5. char *p = s;
6. printf("%c\t%c", p[0], s[1]);
7. }
a) Run time error
b) h h
c) h e
d) h l
Answer: c
Answer: b
62. Which of the following does not initialize ptr to null (assuming variable declaration of a
as int a=0;)?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
Answer: a
1. #include <stdio.h>
2. int x = 0;
3. void main()
4. {
5. int *ptr = &x;
6. printf("%p\n", ptr);
7. x++;
8. printf("%p\n ", ptr);
9. }
a) Same address
b) Different address
c) Compile time error
d) Varies
Answer: a
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. int *ptr = &5;
6. printf("%p\n", ptr);
7. }
a) 5
b) Address of 5
c) Nothing
d) Compile time error
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. int *ptr = &x;
6. printf("%d\n", *ptr);
7. }
a) Address of x
b) Junk value
c) 0
d) Run time error
Answer: c
67. Which of the following can never be sent by call-by-value?
a) Variable
b) Array
c) Structures
d) Both Array and Structures
Answer: b
68. Which type of variables can have the same name in a different function?
a) Global variables
b) Static variables
c) Function arguments
d) Both static variables and Function arguments
Answer: d
69. Arguments that take input by user before running a program are called?
a) Main function arguments
b) Main arguments
c) Command-Line arguments
d) Parameterized arguments
Answer: c
70. What is the maximum number of arguments that can be passed in a single function?
a) 127
b) 253
c) 361
d) No limits in number of arguments
Answer: b
1. #include <stdio.h>
2. void m(int *p, int *q)
3. {
4. int temp = *p; *p = *q; *q = temp;
5. }
6. void main()
7. {
8. int a = 6, b = 5;
9. m(&a, &b);
10. printf("%d %d\n", a, b);
11. }
a) 5 6
b) 6 5
c) 5 5
d) 6 6
Answer: a
1. #include <stdio.h>
2. void m(int *p)
3. {
4. int i = 0;
5. for(i = 0;i < 5; i++)
6. printf("%d\t", p[i]);
7. }
8. void main()
9. {
10. int a[5] = {6, 5, 3};
11. m(&a);
12. }
a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk
Answer: b
1. #include <stdio.h>
2. void m(int p, int q)
3. {
4. int temp = p;
5. p = q;
6. q = temp;
7. }
8. void main()
9. {
10. int a = 6, b = 5;
11. m(a, b);
12. printf("%d %d\n", a, b);
13. }
a) 5 6
b) 5 5
c) 6 5
d) 6 6
Answer: c
74. What will be the output of the following C code?
1. #include <stdio.h>
2. void m(int p, int q)
3. {
4. printf("%d %d\n", p, q);
5. }
6. void main()
7. {
8. int a = 6, b = 5;
9. m(a);
10. }
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d
1. #include <stdio.h>
2. void m(int p)
3. {
4. printf("%d\n", p);
5. }
6. void main()
7. {
8. int a = 6, b = 5;
9. m(a, b);
10. printf("%d %d\n", a, b);
11. }
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d
#include<stdio.h>
#define max 100
main()
{
#ifdef max
printf("hello");
}
a) 100
b) hello
c) “hello”
d) error
Answer: d
77. _______________ is the preprocessor directive which is used to end the scope of #ifdef.
a) #elif
b) #ifndef
c) #endif
d) #if
Answer: c
#include<stdio.h>
void main()
{
#ifndef max
printf("hello");
#endif
printf("hi");
}
a) hello
b) hellohi
c) error
d) hi
Answer: b
#include<stdio.h>
#define san 557
main()
{
#ifndef san
printf("yes");
#endif
printf("no");
}
a) error
b) yes
c) no
d) yesno
Answer: c
80. he preprocessor directive which checks whether a constant expression results in a zero or
non-zero value __________
a) #if
b) #ifdef
c) #undef
d) #ifndef
Answer:a
81. include<stdio.h>
#define max 100
void main()
{
#if(max%10)
printf("san");
#endif
printf("foundry");
}
a) error
b) san
c) foundry
d) sanfoundry
Answer: d
82. The preprocessor directive which is used to remove the definition of an identifier which
was previously defined with #define?
a) #ifdef
b) #undef
c) #ifndef
d) #def
Answer: b
#include<stdio.h>
#define hello 10
void main()
{
printf("%d",hello);
#undef hello
printf("%d",hello);
}
a) 10
b) hello
c) error
d) 1010
Answer: c
#include <stdio.h>
#define a 2
main()
{
int r;
#define a 5
r=a*2;
printf("%d",r);
}
a) 10
b) 4
c) 2
d) 5
Answer: a
85. What will be the output of the following C code if the value of ‘p’ is 10 and that of ‘q’ is
15?
#include<stdio.h>
int main()
{
int p,q;
printf("Enter two numbers\n");
scanf("%d",&p);
scanf("%d",&q);
#if(4<2)
printf("%d",p);
#elif(2>-1)
printf("%d",q);
#else
printf("bye");
#endif
}
a) 10
b) 15
c) bye
d) error
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. double *ptr = (double *)100;
5. ptr = ptr + 2;
6. printf("%u", ptr);
7. }
a) 102
b) 104
c) 108
d) 116
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int *p = (int *)2;
5. int *q = (int *)3;
6. printf("%d", p + q);
7. }
a) 2
b) 3
c) 5
d) Compile time error
Answer: d
88. Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a – b
c) a * b
d) a / b
Answer: b
89. What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
Answer: c
1. #include <stdio.h>
2. void main()
3. {
4. char *s = “hello”;
5. char *p = s;
6. printf(“%c\t%c”, *(p + 1), s[1]);
7. }
a) h e
b) e l
c) h h
d) e e
1. #include <stdio.h>
2. void main()
3. {
4. char *s = "hello";
5. char *p = s;
6. printf("%c\t%c", *p, s[1]);
7. }
a) e h
b) Compile time error
c) h h
d) h e
Answer: d
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. printf("%d%d%d\n", k, *p, **m);
8. }
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Run time error
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. printf("%d%d%d\n", k, *p, **p);
8. }
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. **m = 6;
8. printf("%d\n", k);
9. }
a) 5
b) Compile time error
c) 6
d) Junk
Answer: c
1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. int *r = &p;
7. printf("%d", (**r));
8. }
a) 1
b) Compile time error
c) Address of a
d) Junk value
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. int **r = &p;
7. printf("%p %p", *r, a);
8. }
a) Different address is printed
b) 1 2
c) Same address is printed
d) 1 1
Answer: c
99. . How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 2, c = 3;
5. int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
6. int **sptr = &ptr1; //-Ref
7. *sptr = ptr2;
8. }
a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) none of the mentioned
Answer: b
Unit 1 MCQ with answer (100 No’s)
1. #include <stdio.h>
2. int main()
3. {
4. printf("Hello World! %d \n", x);
5. return 0;
6. }
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
Answer: c
10. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int y = 10000;
5. int y = 34;
6. printf("Hello World! %d\n", y);
7. return 0;
8. }
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
Answer: a
11.Which of the following is not a valid variable name declaration?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int main = 3;
5. printf("%d", main);
6. return 0;
7. }
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
Answer: c
float 3Bedroom-Hall-Kitchen?;
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int ThisIsVariableName = 12;
5. int ThisIsVariablename = 14;
6. printf("%d", ThisIsVariablename);
7. return 0;
8. }
a) The program will print 12
b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time error due to redeclaration
Answer: b
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int a[5] = {1, 2, 3, 4, 5};
5. int i;
6. for (i = 0; i < 5; i++)
7. if ((char)a[i] == '5')
8. printf("%d\n", a[i]);
9. else
10. printf("FAIL\n");
11. }
a) The compiler will flag an error
b) The program will compile and print the output 5
c) The program will compile and print the ASCII value of 5
d) The program will compile and print FAIL for 5 times
Answer: d
17.The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double
Answer: b
18.Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int
Answer: b
Answer: d
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. signed char chr;
5. chr = 128;
6. printf("%d\n", chr);
7. return 0;
8. }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. float f1 = 0.1;
5. if (f1 == 0.1)
6. printf("equal\n");
7. else
8. printf("not equal\n");
9. }
a) equal
b) not equal
c) output depends on the compiler
d) error
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. float f1 = 0.1;
5. if (f1 == 0.1f)
6. printf("equal\n");
7. else
8. printf("not equal\n");
9. }
a) equal
b) not equal
c) output depends on compiler
d) error
Answer: a
25. What will be the output of the following C code on a 32-bit machine?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 10000;
5. double y = 56;
6. int *p = &x;
7. double *q = &y;
8. printf("p and q are %d and %d", sizeof(p), sizeof(q));
9. return 0;
10. }
a) p and q are 4 and 4
b) p and q are 4 and 8
c) compiler error
Answer: a
Answer: c
27. What will be the output of the following C code on a 64 bit machine?
1. #include <stdio.h>
2. union Sti
3. {
4. int nu;
5. char m;
6. };
7. int main()
8. {
9. union Sti s;
10. printf("%d", sizeof(s));
11. return 0;
12. }
a) 8
b) 5
c) 9
d) 4
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. float x = 'a';
5. printf("%f", x);
6. return 0;
7. }
a) a
b) run time error
c) a.0000000
d) 97.000000
Answer: d
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
5. }
a)
C programming Class by
WOW Sanfoundry
C programming Class by
%s Sanfoundry
d) Compilation error
31. In the following code snippet, character pointer str holds a reference to the string
___________
Answer: b
1. #include <stdio.h>
2. #define a 10
3. int main()
4. {
5. const int a = 5;
6. printf("a = %d\n", a);
7. }
a) a = 5
b) a = 10
c) Compilation error
d) Runtime error
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. int var = 010;
5. printf("%d", var);
6. }
a) 2
b) 8
c) 9
d) 10
Answer: b
1. #include <stdio.h>
2. #include <string.h>
3. int main()
4. {
5. char *str = "x";
6. char c = 'x';
7. char ary[1];
8. ary[0] = c;
9. printf("%d %d", strlen(str), strlen(ary));
10. return 0;
11. }
a) 1 1
b) 2 1
c) 2 2
d) 1 (undefined value)
Answer: d
1. #include <stdio.h>
2. void foo(const int *);
3. int main()
4. {
5. const int i = 10;
6. printf("%d ", i);
7. foo(&i);
8. printf("%d", i);
9.
10. }
11. void foo(const int *i)
12. {
13. *i = 20;
14. }
a) Compile time error
b) 10 20
c) Undefined value
d) 10
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. const int i = 10;
5. int *ptr = &i;
6. *ptr = 20;
7. printf("%d\n", i);
8. return 0;
9. }
a) Compile time error
b) Compile time warning and printf displays 20
c) Undefined behaviour
d) 10
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. j = 10;
5. printf("%d\n", j++);
6. return 0;
7. }
a) 10
b) 11
c) Compile time error
d) 0
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. for (int k = 0; k < 10; k++);
5. return 0;
6. }
a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) Error
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. int k;
5. {
6. int k;
7. for (k = 0; k < 10; k++);
8. }
9. }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the C standard implemented by compilers
Answer: a
Answer: a
41.Which of the following format identifier can never be used for the variable var?
1. #include <stdio.h>
2. int main()
3. {
4. char *var = "Advanced Training in C by Sanfoundry.com";
5. }
a) %f
b) %d
c) %c
d) %s
Answer: a
Answer: d
43.Which keyword is used to prevent any changes in the variable within a C program?
a) immutable
b) mutable
c) const
d) volatile
Answer: c
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int k = 4;
5. float k = 4;
6. printf("%d", k)
7. }
a) Compile time error
b) 4
c) 4.0000000
d) 4.4
Answer: a
Answer: c
Answer: b
48.The name of the variable used in one function cannot be used in another function.
a) True
b) False
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int i = -3;
5. int k = i % 2;
6. printf("%d\n", k);
7. }
a) Compile time error
b) -1
c) 1
d) Implementation defined
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int i = 3;
5. int l = i / -2;
6. int k = i % -2;
7. printf("%d %d\n", l, k);
8. return 0;
9. }
a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int i = 5;
5. i = i / 3;
6. printf("%d\n", i);
7. return 0;
8. }
a) Implementation defined
b) 1
c) 3
d) Compile time error
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int i = -5;
5. i = i / 3;
6. printf("%d\n", i);
7. return 0;
8. }
a) Implementation defined
b) -1
c) -3
d) Compile time error
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5 * 9 / 3 + 9;
5. }
a) 3.75
b) Depends on compiler
c) 24
d) 3
Answer: c
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5.3 % 2;
5. printf("Value of x is %d", x);
6. }
a) Value of x is 2.3
b) Value of x is 1
c) Value of x is 0.3
d) Compile time error
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int y = 3;
5. int x = 5 % 2 * 3 / 2;
6. printf("Value of x is %d", x);
7. }
a) Value of x is 1
b) Value of x is 2
c) Value of x is 3
d) Compile time error
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int a = 3;
5. int b = ++a + a++ + --a;
6. printf("Value of b is %d", b);
7. }
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer: d
Answer: a
58. Which of the following is not an arithmetic operation?
a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;
Answer: c
59. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
Answer: d
60. Which among the following are the fundamental arithmetic operators, i.e, performing the
desired operation can be done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10;
5. double b = 5.6;
6. int c;
7. c = a + b;
8. printf("%d", c);
9. }
a) 15
b) 16
c) 15.6
d) 10
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 5;
5. int d;
6. d = a == (b + c);
7. printf("%d", d);
8. }
a) Syntax error
b) 1
c) 10
d) 5
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, y = 0, z = 5;
5. int a = x && y || z++;
6. printf("%d", z);
7. }
a) 6
b) 5
c) 0
d) Varies
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, y = 0, z = 5;
5. int a = x && y && z++;
6. printf("%d", z);
7. }
a) 6
b) 5
c) 0
d) Varies
Answer: b
65.What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1, y = 0, z = 3;
5. x > y ? printf("%d", z) : return z;
6. }
a) 3
b) 1
c) Compile time error
d) Run time error
Answer: c
1. #include <stdio.h>
2. void main()
3. {
4. int x = 1, z = 3;
5. int y = x << 3;
6. printf(" %d\n", y);
7. }
a) -2147483648
b) -1
c) Run time error
d) 8
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0, y = 2, z = 3;
5. int a = x & y | z;
6. printf("%d", a);
7. }
a) 3
b) 0
c) 2
d) Run time error
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10, j = 0;
5. if (i || (j = i + 10))
6. //do something
7. ;
8. }
a) 0
b) 20
c) Compile time error
d) Depends on language standard
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 1;
5. if (i++ && (i == 1))
6. printf("Yes\n");
7. else
8. printf("No\n");
9. }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
Answer: b
Answer: a
72. Do logical operators in the C language are evaluated with the short circuit?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 5;
5. int d;
6. d = b + c == a;
7. printf("%d", d);
8. }
a) Syntax error
b) 1
c) 5
d) 10
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 5, c = 3;
5. b != !a;
6. c = !!a;
7. printf("%d\t%d", b, c);
8. }
a) 5 1
b) 0 3
c) 5 3
d) 1 1
Answer: a
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10;
5. if (a == a--)
6. printf("TRUE 1\t");
7. a = 10;
8. if (a == --a)
9. printf("TRUE 2\t");
10. }
a) TRUE 1
b) TRUE 2
c) TRUE 1 TRUE 2
d) Compiler Dependent
Answer: d
Answer: a
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 1, c;
5. c = a++ + b;
6. printf("%d, %d", a, b);
7. }
a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2
Answer: b
Answer: d
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int a = 10, b = 10;
5. if (a = 5)
6. b--;
7. printf("%d, %d", a, b--);
8. }
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. int j = i++ + i;
6. printf("%d\n", j);
7. }
a) 0
b) 1
c) 2
d) Compile time error
Answer: b
1. #include <stdio.h>
2. int main()
3. {
4. int i = 2;
5. int j = ++i + i;
6. printf("%d\n", j);
7. }
a) 6
b) 5
c) 4
d) Compile time error
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 2;
5. int i = i++ + i;
6. printf("%d\n", i);
7. }
a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. int x = i++, y = ++i;
6. printf("%d % d\n", x, y);
7. return 0;
8. }
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. int *p = &i;
6. printf("%d\n", *p++);
7. }
a) 10
b) 11
c) Garbage value
d) Address of i
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. int y = sizeof(x++);
6. printf("X is %d", x);
7. }
a) X is 97
b) X is 98
c) X is 99
d) Run time error
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4, y, z;
5. y = --x;
6. z = x--;
7. printf("%d%d%d", x, y, z);
8. }
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4;
5. int *p = &x;
6. int *k = p++;
7. int r = p - k;
8. printf("%d", r);
9. }
a) 4
b) 8
c) 1
d) Run time error
Answer: c
1. #include <stdio.h>
2. void main()
3. {
4. int a = 5, b = -7, c = 0, d;
5. d = ++a && ++b || ++c;
6. printf("\n%d%d%d%d", a, b, c, d);
7. }
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
1. #include <stdio.h>
2. void main()
3. {
4. int a = -5;
5. int k = (a++, ++a);
6. printf("%d\n", k);
7. }
a) -4
b) -5
c) 4
d) -3
Answer: d
1. #include <stdio.h>
2. int main()
3. {
4. int c = 2 ^ 3;
5. printf("%d\n", c);
6. }
a) 1
b) 8
c) 9
d) 0
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. unsigned int a = 10;
5. a = ~a;
6. printf("%d\n", a);
7. }
a) -9
b) -10
c) -11
d) 10
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. if (7 & 8)
5. printf("Honesty");
6. if ((~7 & 0x000f) == 8)
7. printf("is the best policy\n");
8. }
a) Honesty is the best policy
b) Honesty
c) is the best policy
d) No output
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. int a = 2;
5. if (a >> 1)
6. printf("%d\n", a);
7. }
a) 0
b) 1
c) 2
d) No Output
Answer: c
1. #include <stdio.h>
2. int main()
3. {
4. int i, n, a = 4;
5. scanf("%d", &n);
6. for (i = 0; i < n; i++)
7. a = a * 2;
8. }
a) Logical Shift left
b) No output
c) Arithmetic Shift right
d) Bitwise exclusive OR
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. int y = sizeof(x++);
6. printf("x is %d", x);
7. }
a) x is 97
b) x is 98
c) x is 99
d) Run time error
Answer: a
1. #include <stdio.h>
2. void main()
3. {
4. int x = 4, y, z;
5. y = --x;
6. z = x--;
7. printf("%d%d%d", x, y, z);
8. }
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
Answer: d