T4Tutorials .PK

VU Past Papers CS201-Paper with Solutions (Spring 2010)

Q#1: In order to get 256 from the number 2568 we divide this number by 10 and take
(A) Its remainder
(B) The number
(C) Its quotient
(D) Its divisor
Answer: (C) Its quotient


Q#2: The correct syntax of do-while loop is
(A) (condition) while; do { statements; };
(B) { statements; } do-while ();
(C) while(condition); do { statements; };
(D) do { statements; } while (condition);
Answer: (D) do { statements; } while (condition);


Q#3: Which of the following function(s) is/are included in stdlib.h header file?
(A) double atof(const char *nptr)
(B) int atoi(const char *nptr)
(C) char *strcpy(char *s1, const char *s2)
(D) 1 and 2 only
Answer: (D) 1 and 2 only


Q#4: If the break statement is missed in a switch statement then
(A) The compiler will give error
(B) This may cause a logical error
(C) No effect on program
(D) Program stops its execution
Answer: (B) This may cause a logical error


Q#5: The data type before a function name represents its
(A) Return Type
(B) Function data
(C) Function arguments
(D) Function name
Answer: (A) Return Type


Q#6: Member function tellg() returns the current location of the ______ pointer.
(A) tellptr()
(B) write()
(C) seekg()
(D) get()
Answer: (D) get()


Q#7: What does 5 | 6 evaluate to in decimal where ‘|’ is bitwise OR operator?

5 = 0101
6 = 0110

Result = 0111 = 7

(A) 3
(B) 4
(C) 5
(D) 7

Answer: (D) 7


Q#8: C is widely known as development language of ______ operating system.
(A) Linux
(B) Windows
(C) Unix
(D) Mac OS
Answer: (C) Unix


Q#9: What will be the result of arithmetic expression 6 + 27 / 3 × 3 ?

First division → 27 / 3 = 9
Then multiplication → 9 × 3 = 27
Then addition → 6 + 27 = 33

(A) 33
(B) 45
(C) 9
(D) 30

Answer: (A) 33


Q#10: How many bytes are occupied by the array

char str[] = “programming”;

Characters = 11
Null character = 1

Total = 12 bytes

(A) 10
(B) 11
(C) 12
(D) 13

Answer: (C) 12


Q#11: Correct syntax to initialize pointer ptr with string “programming”

(A) char ptr = ‘programming’;
(B) char *ptr = “programming”;
(C) char *ptr = ‘programming’;
(D) *ptr = “programming”;

Answer: (B) char *ptr = “programming”;


Q#12: What will be the result of expression x %= 2 if x = 7?

7 % 2 = 1

(A) x = 1
(B) x = 3
(C) x = 7
(D) x = 2

Answer: (A) x = 1


Q#13: UNIX has been developed in ______ language.

(A) JAVA
(B) B
(C) C
(D) FORTRAN

Answer: (C) C


Q#14: Declaring structures does not mean that memory is allocated.

(A) True
(B) False

Answer: (A) True


Q#15: What will be the value of i and j in the following code?

int x[5] = {2,3,4,8,9};
int *ptr = &x[2];

i = (*ptr)++;
j = *ptr++;

(A) i = 5, j = 5
(B) i = 5, j = 8
(C) i = 4, j = 8
(D) i = 5, j = 9

Answer: (C) i = 4, j = 8


Q#16: When an array element is passed to a function, it is passed by

(A) reference
(B) data type
(C) value
(D) data

Answer: (C) value


Q#17: What is the difference between switch statement and if statement?

Answer:
The switch statement is used to select one option from multiple cases based on the value of a single variable or expression.
The if statement is used to check conditions and can evaluate multiple logical expressions.


Q#18: Why do we close a file after use?

Answer:
A file is closed after use to save the changes, free system resources, and ensure data is properly stored in the file.


Q#19: A two-dimensional array has 3 rows and 4 columns. Write syntax to initialize first element of all three rows with value 2.

Answer:

matrix[0][0] = 2
matrix[1][0] = 2
matrix[2][0] = 2


Q#20: Identify errors in the code

main()
{
int x = 10
const int *ptr = &x;
*ptr = 5;
}

Errors:

  1. Missing semicolon after int x = 10
  2. Pointer ptr is pointing to constant integer data, so *ptr = 5 is not allowed.

Q#21: Can you use assignment operator to assign one C-string to another?

Answer:
No. In C/C++ we cannot directly assign one C-string to another using = operator. Instead, we use string functions such as strcpy().


Q#22: Why is binary search more efficient than linear search?

Answer:
Binary search is more efficient because it uses divide-and-conquer technique. It repeatedly divides the sorted array into halves, reducing the number of comparisons.
For example, in an array of 1000 elements, linear search may take up to 1000 comparisons, while binary search takes about 10 comparisons.


Q#23: Write the output of the given union program

Size of char = 1 byte
Size of int = 2 bytes
Size of float = 4 bytes

A union stores all members in the same memory location, so its size equals the largest data type.

Largest type = float = 4 bytes

Output:

4

4

Exit mobile version