UGC-NET Dec 2014 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0069

When an array is passed as parameter to a function, which of the following statements is correct ?
  1. A
    The function can change values in the original array.
  2. B
    In $C$, parameters are passed by value, the function cannot change the original value in the array.
  3. C
    It results in compilation error when the function tries to access the elements in the array.
  4. D
    Results in a run time error when the function tries to access the elements in the array.

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionWhen an array is passed, C passes the address of its first element (the array name decays to a pointer). The function works on the caller's elements through that pointer, so assignments inside the function change the original array.(B) The pointer itself is passed by value, but it still points to the original elements — incorrect.(C), (D) Accessing the elements is legal and causes no compile-time or run-time error — incorrect.Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com