C Arrays Questions and Answers

Practice Mode
Showing 10 of 50 questions
Q31
The value within the [ ] in an array variable specifies
  • A subscript value
  • B size of the array
  • C value of the array element
  • D array bount
Answer: Option A
Q32
In a multi-dimensional array with initialization
  • A The rightmost dimension may be omitted
  • B The leftmost dimension may be omitted.
  • C Nothing must be omitted.
  • D All may be omitted.
Answer: Option B
Q33
When should an array be used ?
  • A When we need to hold variable constants.
  • B When we need to hold data of the same type
  • C When we need to obtain automatic memory cleanup functionality.
  • D When we need to hold data of different types.
Answer: Option B
Q34
x [2] = 5; 2 [x] = 5; Are x [2] and 2[x] identical in the sample code above ? why or why not ?
  • A No. Both variable assignments have invalid syntax.
  • B No. x[2] is correct, but 2[x] is invalid syntax.
  • C Yes. Both are identical because they are resolved to pointer references.
  • D No. 2[x] is correct, but x[2] is invalid syntax.
Answer: Option C
Q35
main ( )  { int a [100], i; for ( i = 1 ; i <= 100; ++i) { ...   ;   }
  • A The above loop statement is incorrect since the last valid subscript of a is 99
  • B The above loop statement is incorrect i is not initializedto 0.
  • C The above loop statement is correct.
  • D The above loop statement is incorrect since i is pre-incremented.
Answer: Option C
Q36
Char sub [ 10] = ???? ; which of the following statements cannot be used to replace the ???? in the above syntax to initialize sub with string "Maths"?
  • A { "Maths"}
  • B {'M', 'a' , 't', 'h', 's', '\0'}
  • C {'M' "aths"}
  • D {"Mat" "hs"}
Answer: Option C
Q37
main ( ) { const int size = 5; int i, n, line [size]; for (i = 0; i< n; i++) { line [ i ] = i; } } What will happen when the sample code fragment above is executed ?
  • A The array will be initialized with the numbers 0 through 39.
  • B The code will not compile.
  • C The code will compile with warnings.
  • D the code will compile, but not link.
Answer: Option B
Q38
Which of the following macros would properly return the number of elements in an array (not a pointer, an actual array )?
  • A # define NUM_ELEM (x) (sizeof (x)/size of (x[0]))
  • B # define NUM ELEM (x) (size of (X))
  • C # define NUM ELEM (x) (sizeof (x()/size of (x[0]))
  • D #include <stdio.h>
Answer: Option D
Q39
main ( ) { char sl [ 100]; char s2 [100]; gets (s1); fgets ( s2, sizeof (s2), stdin ); printf (&quot;%d\n&quot;, strlen (s1) - strlen (s2)); } What will be printed when the above code is executed and the string &quot;abcd&quot; is entered twice on stdin ?
  • A -1
  • B 0
  • C 1
  • D 4
Answer: Option A
Q40
int booklet [3] [2] [2] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, }; What value does booklet [2][1][0] in the sample code above contain ?
  • A 5
  • B 7
  • C 9
  • D 11
Answer: Option D
Questions and Answers for Competitive Exams Various Entrance Test