0% found this document useful (0 votes)
17 views19 pages

C Programming and Data Structures Guide

The document contains a series of questions and answers related to programming in C and data structures, covering topics such as keywords, function signatures, memory allocation, and data structures like linked lists and trees. It includes multiple-choice questions that test knowledge on C programming concepts, syntax, and data structure properties. The document serves as a study guide or quiz for individuals learning C programming and data structures.

Uploaded by

penchalaiah550
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)
17 views19 pages

C Programming and Data Structures Guide

The document contains a series of questions and answers related to programming in C and data structures, covering topics such as keywords, function signatures, memory allocation, and data structures like linked lists and trees. It includes multiple-choice questions that test knowledge on C programming concepts, syntax, and data structure properties. The document serves as a study guide or quiz for individuals learning C programming and data structures.

Uploaded by

penchalaiah550
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

Programming in C and Data Structures

1. Which of the following is an important requirement of c programming?


a) Function
b) Input variables
c) Output variables
d) All of the above
Ans. A

2. What is the purpose of the `volatile` keyword in C programming?


a) It indicates that a variable’s value may change at any time without any
action being taken by the code.
b) It specifies that a variable cannot be modified.
c) It forces the compiler to optimize the variable aggressively.
d) It is used to define constant values.
Answer: A

3. What is the purpose of the `static` keyword when applied to a local


variable in C?
a) It makes the variable global.
b) It allocates memory on the heap.
c) It preserves the variable’s value between function calls.
d) It initializes the variable to zero.
Answer: C

4. What is the purpose of the `#pragma` directive in C?


a) It is used to define macros.
b) It is used for conditional compilation.
c) It is used for compiler-specific instructions.
d) It is used for loop control.
Answer: C

5. What is the output of the following code snippet?


#include <stdio.h>
int main() {
char str[] = “Hello, World!”;
printf(“%s”, str + 7);
return 0;
}
a) “Hello, World!”
b) “World!”
c) “World!”
d) “ello, World!”
Answer: B
6. In C, _________ operator is used for bitwise OR?
a) | (pipe)
b) |& (pipe-ampersand)
c) |* (pipe-asterisk)
d) || (logical OR)
Answer: A

7. What is the purpose of the `int main(int argc, char* argv[])` function
signature in C?
a) It specifies a function to take integer arguments.
b) It is the entry point of a C program that accepts command-line
arguments.
c) It defines a function with no arguments.
d) It is used for memory allocation.
Answer: B

8. __________________ C library function is used for converting a string to an


integer?
a) str2int()
b) atoi()
c) itoa()
d) int2str()
Answer: B

9. How many times the program will print "Algbly"?

int main() {
printf("Algbly");
main();
return 0;
}
a) Infinite times
b) 32767 times
c) 65535 times
d) Till stack overflows
Ans. D

10. function „p‟ that accepts a pointer to a character as argument and


return a pointer to an array of
integer can be declared as
A. int (*p(char*))[ ]
B. int *p(char *)[ ]
C. int (*p)(char *)[ ]
D. None of these
Ans. A
11. What is (void*)0 ?
A. Representation of NULL pointer
B. Representation of void pointer
C. Error
D. None of above
Ans. A
12. The pointer ptr points to the which string?
char *ptr
char mystring[]=”letsfind”;
ptr = mystring;
ptr +=5;
A. find
B. ind
C. letsf
D. f
Ans. B
13. which of the following is true about FILE *fp;
A. FILE is a keyword in C for representing files and fp is a variable of FILE type.
B. FILE is a stream
C. FILE is a buffered stream
D. FILE is a structure and fp is a pointer to the structure of FILE type.
Ans. D
14. Consider the program below in a hypothetical
programming language which allows global variables and a choice of
static or dynamic scoping
int i;
program Main( )
{
i = 10;
call f ( );
}
procedure f( )
{
int i = 20;
call g ( );
}
procedure g( )
{
print i;
}
Let x be the value printed under static scoping and y be the value printed under
dynamic scoping. Then x and y are
a) x = 10, y = 20
b) x = 20, y = 10
c) x = 20, y = 20
d) x = 10, y = 10
Ans. D
15. The correct way to round off a floating number x to an integer value is
a) y = (int) (x + 0.5)
b) y = int (x + 0.5)
c) y = (int) x + 0.5
d) y = (int)((int)x + 0.5)
Ans. A
16. What does the following expression means?
char *(*(*a[N]) ()) ();
a) a pointer to a function returning array of n pointers to function returning
character pointers
b) a function return array of N pointers to functions returning pointers to characters
c) an array of n pointers to function returning pointers to characters
d) an array of n pointers to function returning pointers to functions
returning pointers to characters
Ans. D
17. Which of the following differentiates between overloaded functions
and overridden functions?
a) Overloading is a dynamic or runtime binding and overridden is a static or compile
time binding.
b) Overloading is a static or compile time binding and overriding is
dynamic or runtime binding.
c) Redefining a function in a friend class is called overloading, while redefining a
function in a derived class is called as overridden function.
d) Redefining a function in a derived class is called function overloading, while
redefining a function in a friend class is called function overriding.
Ans. B

18. Consider the following statements S1, S2 and S3 :


S1 : In call-by-value, anything that is passed into a function call is
unchanged in the caller's scope when the function returns.
S2: In call-by-reference, a function receives implicit reference to a variable
used as argument.
S3: In call-by-reference, caller is unable to see the modified variable used
as argument.
a) S3 and S2 are true
b) S3 and S1 are true
c) S2 and S1 are true
d) S1, S2, S3 are true
Ans. D
19. What is the output of the following program ?
(Assume that the appropriate preprocessor directives are included and there is no
syntax error)
main ( )
{ char S[ ] = "ABCDEFGH";
printf ("%C",* (& S[3]));
printf ("%s", S + 4);
printf ("%u", S);
/* Base address of S is 1000 */
}
a) ABCDEFGH1000
b) CDEFGH1000
c) DDEFGHH1000
d) DEFGH1000
Ans. B
20. Assume that x and y are non-zero positive integers. What does the
following program segment perform?
while (x!=0)
{
if (x>y)
x = x-y
else
y=y-x;
printf(“%d”,x);

a) Computes LCM of two numbers


b) Computes GCD of two numbers
c) Divides large number with small number
d) Subtracts smaller number from large number
Ans. B
21. A Program contains the following declarations and initial
assignments:
int i = 8, j = 5;
double x = 0.005, y = –0.01;
char c=’c’, d=’d’;
Determine the value of the following expressions which involve the use of library
functions:
abs(i-2*j) ; log(exp(x)) ; toupper(d)
a) 2; 0.005; D
b) 1; 0.005; D
c) 2; 0.005; E
d) 1; 0.005; e
Ans. A
22. What would be the output of the following program, if run from the
command line as “myprog 1 2 3”?
main (int argc, char * argv[ ])
{ int i ;
i = argv[1] + argv[2] + argv[3] ;
printf (“% d”, i) ;
}
a) 123
b) 6
c) Error
d) “123”
Ans. C
23. In case of right shift bitwise operator in ‘C’ language, after shifting n
bits, the left most n bits:
a) are always filled with zeroes
b) are always filled with ones
c) are filled with zeroes or ones and is machine dependent
d) none of the above
Ans. C

24. When one-dimensional character array of unspecified length is


assigned an initial value:
a) an arbitrary character is automatically added to the end of the string
b) ‘o’ is added to the end of the string
c) length of the string is added to the end of the string
d) ‘end’ is added to the end of the string
Ans. B
25. #define max(x,y) x=(x>y)?x:y
is a macro definition, which can find the maximum of two numbers x and y
if:
a) x and y are both integers only
b) x and y are both declared as float only
c) x and y are both declared as double only
d) x and y are both integers, float or double
Ans. D
26. Consider the following pseudo-code fragment, where m is a non-
negative integer that has been initialized.
Which of the following is a loop invariant for the while statement?
(Note: a loop invariant for a while statement is an assertion that is true each time
the guard is evaluated during the execution of the while statement).
p=0
k=0
while (k<m)
p = p + 2k
k=k+1
end while
a) p = 2^k − 1 and 0≤k<m
b) p = 2^(k+1) − 1 and 0≤k<m
c) p = 2^k − 1 and 0≤k≤m
d) p = 2^(k+1) − 1 and 0≤k≤m
Ans. C

1 .Minimum number of fields in each node of a doubly linked list is ____


(A) 2
(B) 3
(C) 4
(D) None of the above
Ans: B
2. A graph in which all vertices have equal degree is known as ____
(A) Complete graph
(B) Regular graph
(C) Multi graph
(D) Simple graph
Ans: A
3. A vertex of in-degree zero in a directed graph is called
a/an__________________
(A) Root vertex
(B) Isolated vertex
(C) Sink
(D) Articulation point
Ans: C
4. A graph is a tree if and only if graph is __________________
(A) Directed graph
(B) Contains no cycles
(C) Planar
(D) Completely connected
Ans: B
5. The elements of a linked list are stored_________________
(A) In a structure
(B) In an array
(C) Anywhere the computer has space for them
(D) In contiguous memory locations
Ans: C

6. A parentheses checker program would be best implemented using


(A) List
(B) Queue
(C) Stack
(D) Any of the above
Ans: C
7. To perform level-order traversal on a binary tree, which of the following
data structure will be required?
(A) Hash table
(B) Queue
(C) Binary search tree
(D) Stack
Ans: B
8. Which of the following data structure is required to convert arithmetic
expression in infix to its equivalent postfix notation?
(A) Queue
(B) Linked list
(C) Binary search tree
(D) None of above
Ans: D
9. A binary tree in which all its levels except the last, have maximum
numbers of nodes, and all the nodes in the last level have only one child it
will be its left child. Name the tree.
(A) Threaded tree
(B) Complete binary tree
(C) M-way search tree
(D) Full binary tree
Ans: B
10. Which of following data structure is more appropriate for
implementing quick sort iteratively?
(A) Deque
(B) Queue
(C) Stack
(D) Priority queue
Ans: C
11. The number of edges in a complete graph of n vertices is
(A) n(n+1)/2
(B) n(n-1)/2
(C) n2/2
(D) n
Ans: B
12. If two trees have same structure and but different node content, then
they are called ___
(A) Synonyms trees
(B) Joint trees
(C) Equivalent trees
(D) Similar trees
Ans: D
13. If two trees have same structure and node content, then they are
called ____
(A) Synonyms trees
(B) Joint trees
(C) Equivalent trees
(D) Similar trees
Ans: C
14. Finding the location of a given item in a collection of items is called
……
A. Discovering
B. Finding
C. Searching
D. Mining
Ans. C
15. The time complexity of quicksort is ……..
A. O(n)
B. O(logn)
C. O(n2)
D. O(n logn)
Ans. D

16. Quick sort is also known as ……..


A. merge sort
B. tree sort
C. shell sort
D. partition and exchange sort
Ans. D
17. ………. sorting is good to use when alphabetizing a large list of names.
A. Merge
B. Heap
C. Radix
D. Bubble
Ans. C
18. The total number of comparisons in a bubble sort is ….
A. O(n logn)
B. O(2n)
C. O(n2)
D. O(n)
Ans. A
19. ……… form of access is used to add and remove nodes from a queue.
A. LIFO, Last In First Out
B. FIFO, First In First Out
C. Both a and b
D. None of these
Ans. B
20. New nodes are added to the ……… of the queue.
A. Front
B. Back
C. Middle
D. Both A and B
Ans. B

21. The term push and pop is related to_________________


A. Array
B. Lists
C. Stacks
D. Trees
Ans. C
22. Which of the following is an application of stack?
A. finding factorial
B. tower of Hanoi
C. infix to postfix
D. all of the above
Ans. D
23. The operation of processing each element in the list is known as ……
A. sorting
B. merging
C. inserting
D. traversal
Ans. D
24. The situation when in a linked list START=NULL is ….
A. Underflow
B. Overflow
C. Houseful
D. Saturated
Ans. A
25. Which of the following are two-way lists?
A. Grounded header list
B. Circular header list
C. Linked list with header and trailer nodes
D. List traversed in two directions
Ans. D

26. Which is the pointer associated with the availability list?


A. FIRST
B. AVAIL
C. TOP
D. REAR
Ans. B
27. Which of the following data structure can’t store the non-
homogeneous data elements?
A) Arrays
B) Records
C) Pointers
D) Stacks
Ans. A
28. Which of the following is non-liner data structure?
A) Stacks
B) List
C) Strings
D) Trees
Ans. D
29. To represent hierarchical relationship between elements, which data
structure is suitable?
A) Dequeue
B) Priority
C) Tree
D) Graph
Ans. C
30. Identify the data structure which allows deletions at both ends of the
list but insertion at only one end.
A) Input restricted dequeue
B) Output restricted qequeue
C) Priority queues
D) Stack
Ans. A

31. What is the value of the postfix expression 6 3 2 4 + – *?


a) 74
b) -18
c) 22
d) 40
Ans. B
32. The prefix form of A-B/ (C * D ^ E) is?
a) -A/B*C^DE
b) -A/BC*^DE
c) -ABCD*^DE
d) -/*^ACBDE
Ans. A
33. Which of the following points is/are not true about Linked List data
structure when it is compared with an array?
a) Random access is not allowed in a typical implementation of Linked Lists
b) Access of elements in linked list takes less time than compared to
arrays
c) Arrays have better cache locality that can make them better in terms of
performance
d) It is easy to insert and delete elements in Linked List
Ans. B
34. What will be the output of the following program?
main()
{ char str[]="san foundry";
int len = strlen(str);
int i;
for(i=0;i<len;i++)
push(str[i]); // pushes an element into stack
for(i=0;i<len;i++)
pop(); //pops an element from the stack
}
a) yrdnuof nas
b) foundry nas
c) sanfoundry
d) san foundry
Ans. A
35. A data structure in which elements can be inserted or deleted at/from
both ends but not in the middle is?
a) Priority queue
b) Dequeue
c) Circular queue
d) Queue
Ans. B
36. For getting best time complexity in the worst case scenario, which
type of sorting algorithms are used?
a) Bubble sort of algorithm
b) Selection sort of algorithm
c) Quick sort of algorithm
d) Merge sort of algorithm
Ans. D
37. Given an empty stack, after performing push (1), push (2), Pop, push
(3), push (4), Pop, Pop, push(5), Pop, what is the value of the top of the
stack ?
a) 4
b) 3
c) 2
d) 1
Ans. D
38. Suppose there are logn sorted lists of n logn elements each. The time
complexity of producing a sorted list of all these elements is (use heap
data structure)
a) (n log logn)
b) θ(n logn)
c) Ω(n logn)
d) Ω(n3/2)
Ans. A
39. If the queue is implemented with a linked list, keeping track of a front
pointer and a rear pointer, which of these pointers will change during an
insertion into a non-empty queue?
a) Neither of the pointers change
b) Only front pointer changes
c) Only rear pointer changes
d) Both of the pointers changes
Ans. C

40. For any B-tree of minimum degree t ≥ 2, every node other than the
root must have atleast keys and every node can have at most ____ keys.
a) t -1, 2t + 1
b) t + 1, 2t + 1
c) t-1, 2t-1
d) t+ 1, 2t-1
Ans. C
41. How many PUSH and POP operations will be needed to evaluate the
following expression by reverse polish notation in a stack machine (A * B)
+ (C * D/E)?
a) 4 PUSH and 3 POP instructions
b) 5 PUSH and 4 POP instructions
c) 6 PUSH and 2 POP instructions
d) 5 PUSH and 3 POP instructions
Ans. B
42. Consider an array A[20. 10], assume 4 words per memory cell and the
base address of array A is 100. What is the address of A[11,5]? Assume
row major storage.
a) 560
b) 565
c) 570
d) 575
Ans. A
43. Suppose that we have numbers between 1 and 1000 in a binary search
tree and we want to search for the number 365. Which of the following
sequences could not be the sequence of nodes examined ?
a) 4, 254,403, 400,332,346, 399, 365
b) 926,222,913,246,900,260,364,365
c) 927,204,913, 242,914,247,365
d) 4,401,389,221,268, 384,383, 280,365
Ans. C
44. Which of the following is a valid heap?

a) A
b) B
c) C
d) D
Ans. B
45. Consider an undirected graph G where self-loops are not allowed.
The vertex set of G is {(i, j) | 1 ≤ i ≤ 12, 1 ≤ j ≤ 12}. There is an edge
between (a, b) and (c, d) if |a – c| ≤ 1 or |b–d| ≤ 1. The number of edges
in this graph is
a) 726
b) 796
c) 506
d) 616
Ans. D
46. Consider the following binary search tree. If we remove the root
node, which of the node from the left subtree will be the new root?

a) 11
b) 12
c) 13
d) 16
Ans. D
47. In the following graph, discovery time stamps and finishing time
stamps of Depth First Search (DFS) are shown as x/y where x is discovery
time stamp and y is finishing time stamp.
It shows which of the following depth first forest?

a) {a,b,e} {c,d,f,g,h}
b) {a,b,e} {c,d,h} {f,g}
c) {a,b,e} {f,g} {c,d} {h}
d) {a,b,c,d} {e,f,g} {h}
Ans. A
48. Consider the following statements:
(i) A graph in which there is a unique path between every pair of vertices is a tree.
(ii) A connected graph with e = v – 1 is a tree.
(iii) A graph with e = v – 1 that has no circuit is a tree.
Which of the above statements is/are true?
a) (i) & (iii)
b) (ii) & (iii)
c) (i) & (ii)
d) All of the above
Ans. D
49. Consider the In-order and Post-order traversals of a tree as given
below:
In-order: j e n k o p b f a c l g m d h i
Post-order: j n o p k e f b c l m g h i d a
The Pre-order traversal of the tree shall be
a) abfejknopcdglmhi
b) abcdefjknopglmhi
c) abejknopfcdglmhi
d) jenopkfbclmghida
Ans. C
50. Given a binary search trees for a set of n=5 keys with the following
probabilities. The expected optimal cost of the search is

a) 2.65
b) 2.70
c) 2.75
d) 2.80
Ans. C

51. G1 and G2 are two graphs as shown below


a. Both G1 and G2 are planar graphs.
b. Both G1 and G2 are not planar graphs.
c. G1 is planar and G2 is not planar graph.
d. G1 is not planar and G2 is planar graph.
Ans. D
52. In a B tree of order 5, the following keys are inserted as follows :
7, 8, 1, 4, 13, 20, 2, 6 and 5
How many elements are present in the root of the tree?
a) 1
b) 2
c) 3
d) 4
Ans. B
53. With regard to linked list, which of the following statement is false?
a) An algorithm to search for an element in a singly linked list requires 0(n)
operations in the worst case.
b) An algorithm for deleting the first element in a singly linked list
requires 0(n) operations in the worst case.
c) An algorithm for finding the maximum value in a circular linked list requires
0(n) operations.
d) An algorithm for deleting the middle node of a circular linked list requires 0(n)
operations.
Ans. B
54. If (rear==maxsize-1) rear=0; else rear=rear+1; is required in:
a) circular queue
b) linear queue
c) stack
d) deque
Ans. D

You might also like