FSc · Computer Science (Grade 12)

Unit 5 MCQs

50 solved multiple choice questions with answers.

Q1. An array is

  1. AA function
  2. BA single variable
  3. CA collection of different data types
  4. DA collection of elements of the same data type
Show answer
Answer: D. A collection of elements of the same data type
Report a mistake

Q2. Array elements are stored in

  1. AStack only
  2. BRandom memory locations
  3. CHeap only
  4. DContiguous memory locations
Show answer
Answer: D. Contiguous memory locations
Report a mistake

Q3. The index of the first element of an array is

  1. A1
  2. B–1
  3. C0
  4. DAny number
Show answer
Answer: C. 0
Report a mistake

Q4. The size of an array must be

  1. AA character
  2. BA constant integer expression
  3. CA float
  4. DA variable
Show answer
Answer: B. A constant integer expression
Report a mistake

Q5. Declaration of a one-dimensional array is

  1. ANone
  2. Barray_name[size] data_type;
  3. Cdata_type array_name[size];
  4. Dsize array_name data_type;
Show answer
Answer: C. data_type array_name[size];
Report a mistake

Q6. Two-dimensional array is also called

  1. AList
  2. BTree
  3. CMatrix
  4. DVector
Show answer
Answer: C. Matrix
Report a mistake

Q7. A string in C++ is

  1. AA single character
  2. BA float array
  3. CAn array of characters terminated by null character ‘\0’
  4. DAn integer array
Show answer
Answer: C. An array of characters terminated by null character ‘\0’
Report a mistake

Q8. The null character is represented as

  1. A‘ ’
  2. B‘\0’
  3. C‘\t’
  4. D‘\n’
Show answer
Answer: B. ‘\0’
Report a mistake

Q9. Strings can be declared using

  1. Achar array or string class
  2. BOnly float
  3. COnly int array
  4. DOnly bool
Show answer
Answer: A. char array or string class
Report a mistake

Q10. Commonly used string functions are found in

  1. A<iostream>
  2. B<cstring> or <string.h>
  3. C<cmath>
  4. D<cstdlib>
Show answer
Answer: B. <cstring> or <string.h>
Report a mistake

Q11. strlen() function returns

  1. ANone
  2. BSize of array
  3. CLength of the string (excluding null character)
  4. DCapacity
Show answer
Answer: C. Length of the string (excluding null character)
Report a mistake

Q12. strcpy() function is used to

  1. AConcatenate
  2. BCopy one string into another
  3. CFind length
  4. DCompare two strings
Show answer
Answer: B. Copy one string into another
Report a mistake

Q13. The last valid index of an array of size n is

  1. A0
  2. Bn+1
  3. Cn
  4. Dn–1
Show answer
Answer: D. n–1
Report a mistake

Q14. Accessing array element beyond its size causes

  1. AUndefined behavior / Runtime error
  2. BAutomatic resizing
  3. CCompile-time error always
  4. DNo problem
Show answer
Answer: A. Undefined behavior / Runtime error
Report a mistake

Q15. Initialization of array can be done

  1. AAt the time of declaration
  2. BNever
  3. COnly with zeros
  4. DOnly later
Show answer
Answer: A. At the time of declaration
Report a mistake

Q16. int arr[5] = {1,2,3}; remaining elements become

  1. AGarbage
  2. B–1
  3. C1
  4. D0
Show answer
Answer: D. 0
Report a mistake

Q17. int arr[] = {1,2,3,4,5}; size is

  1. A6
  2. B4
  3. C5
  4. DUnknown
Show answer
Answer: C. 5
Report a mistake

Q18. To find number of elements in array we use

  1. Asize(arr)
  2. Blength(arr)
  3. Csizeof(arr)/sizeof(arr[0])
  4. Dstrlen(arr)
Show answer
Answer: C. sizeof(arr)/sizeof(arr[0])
Report a mistake

Q19. Two-dimensional array declaration is

  1. Adata_type array_name[rows][columns];
  2. Barray_name[rows][columns] data_type;
  3. CNone
  4. Ddata_type array_name[columns][rows];
Show answer
Answer: A. data_type array_name[rows][columns];
Report a mistake

Q20. Elements of 2D array are stored in

  1. ARow-major order (usually)
  2. BColumn-major only
  3. CStack only
  4. DRandom order
Show answer
Answer: A. Row-major order (usually)
Report a mistake

Q21. To access element at row i, column j we write

  1. Aarr[i][j]
  2. Barr[i,j]
  3. Carr(i,j)
  4. Darr{i}{j}
Show answer
Answer: A. arr[i][j]
Report a mistake

Q22. A string is terminated by

  1. ANewline
  2. BSpace
  3. CEnd of file
  4. DNull character ‘\0’
Show answer
Answer: D. Null character ‘\0’
Report a mistake

Q23. char str[10] = "Hello"; occupies

  1. A10 bytes fully used
  2. B5 bytes
  3. C6 bytes (5 chars + null)
  4. D11 bytes
Show answer
Answer: C. 6 bytes (5 chars + null)
Report a mistake

Q24. strlen("Hello") returns

  1. A6
  2. B5
  3. C10
  4. D4
Show answer
Answer: B. 5
Report a mistake

Q25. strcpy(dest, src) copies

  1. Adest into src
  2. BBoth ways
  3. Csrc into dest
  4. DNone
Show answer
Answer: C. src into dest
Report a mistake

Q26. strcat(dest, src) is used to

  1. ACopy strings
  2. BFind length
  3. CCompare strings
  4. DConcatenate src at the end of dest
Show answer
Answer: D. Concatenate src at the end of dest
Report a mistake

Q27. strcmp(str1, str2) returns

  1. AAlways 0
  2. BLength difference only
  3. C0 if equal, <0 if str1 < str2, >0 if str1 > str2
  4. DAlways 1
Show answer
Answer: C. 0 if equal, <0 if str1 < str2, >0 if str1 > str2
Report a mistake

Q28. strrev() is used to

  1. AFind length
  2. BCopy strings
  3. CCompare strings
  4. DReverse a string
Show answer
Answer: D. Reverse a string
Report a mistake

Q29. strlwr() converts string to

  1. ATitle case
  2. BLowercase
  3. CUppercase
  4. DNone
Show answer
Answer: B. Lowercase
Report a mistake

Q30. strupr() converts string to

  1. ALowercase
  2. BTitle case
  3. CNone
  4. DUppercase
Show answer
Answer: D. Uppercase
Report a mistake

Q31. gets() function is used to

  1. ARead only one word
  2. BRead a string (including spaces)
  3. CClear screen
  4. DWrite a string
Show answer
Answer: B. Read a string (including spaces)
Report a mistake

Q32. puts() function is used to

  1. ACompare strings
  2. BRead a string
  3. CCopy strings
  4. DDisplay a string followed by newline
Show answer
Answer: D. Display a string followed by newline
Report a mistake

Q33. cin >> str; stops reading at

  1. AEnd of line only
  2. BFirst whitespace
  3. CNull character
  4. DNever stops
Show answer
Answer: B. First whitespace
Report a mistake

Q34. To read a full line with spaces we can use

  1. AOnly cout
  2. BOnly cin >>
  3. Ccin.getline() or gets()
  4. DNone
Show answer
Answer: C. cin.getline() or gets()
Report a mistake

Q35. Array name itself represents

  1. AValue of first element
  2. BBase address of the array
  3. CSize of array
  4. DLast element
Show answer
Answer: B. Base address of the array
Report a mistake

Q36. Passing array to a function actually passes

  1. ANone
  2. BBase address (by reference)
  3. CCopy of entire array
  4. DSize only
Show answer
Answer: B. Base address (by reference)
Report a mistake

Q37. Multidimensional arrays can have

  1. AMore than two dimensions
  2. BOnly two dimensions
  3. COnly one dimension
  4. DNone
Show answer
Answer: A. More than two dimensions
Report a mistake

Q38. The size of char array to store a string of length n must be at least

  1. An+1
  2. Bn–1
  3. C2n
  4. Dn
Show answer
Answer: A. n+1
Report a mistake

Q39. "Hello" is a

  1. ACharacter literal
  2. BFloat literal
  3. CString literal
  4. DInteger literal
Show answer
Answer: C. String literal
Report a mistake

Q40. Character literal is written in

  1. ABoth same
  2. BDouble quotes "A"
  3. CNo quotes
  4. DSingle quotes ‘A’
Show answer
Answer: D. Single quotes ‘A’
Report a mistake

Q41. String literal is written in

  1. ADouble quotes "Hello"
  2. BBoth same
  3. CNo quotes
  4. DSingle quotes ‘Hello’
Show answer
Answer: A. Double quotes "Hello"
Report a mistake

Q42. Array of strings can be declared as

  1. AOnly float arr[]
  2. BOnly int arr[]
  3. CNone
  4. Dchar arr[][20] or string arr[]
Show answer
Answer: D. char arr[][20] or string arr[]
Report a mistake

Q43. Out-of-bounds access in array

  1. AIs always detected at compile time
  2. BIs safe
  3. CIncreases performance
  4. DShould be avoided (leads to bugs)
Show answer
Answer: D. Should be avoided (leads to bugs)
Report a mistake

Q44. Dynamic arrays in C++ can be created using

  1. Anew operator or vectors
  2. BOnly stack
  3. COnly static declaration
  4. DNone
Show answer
Answer: A. new operator or vectors
Report a mistake

Q45. The header for string class is

  1. A<iostream>
  2. B<cstdlib>
  3. C<string>
  4. D<cstring>
Show answer
Answer: C. <string>
Report a mistake

Q46. string class provides

  1. AOnly characters
  2. BSafer and more flexible string handling
  3. CNone
  4. DOnly C-style strings
Show answer
Answer: B. Safer and more flexible string handling
Report a mistake

Q47. Length of a string object can be found by

  1. Astr.length() or str.size()
  2. BOnly strlen()
  3. COnly sizeof
  4. DNone
Show answer
Answer: A. str.length() or str.size()
Report a mistake

Q48. Comparing two string objects can be done with

  1. AOnly =
  2. BOnly strcmp
  3. C==, !=, <, >, <=, >=
  4. DNone
Show answer
Answer: C. ==, !=, <, >, <=, >=
Report a mistake

Q49. Arrays are useful for

  1. AStoring different types
  2. BStoring multiple values of same type under one name
  3. COnly functions
  4. DOnly single values
Show answer
Answer: B. Storing multiple values of same type under one name
Report a mistake

Q50. Strings are useful for

  1. AOnly boolean values
  2. BHandling text data
  3. COnly numbers
  4. DOnly memory addresses
Show answer
Answer: B. Handling text data
Report a mistake