UGC-NET Jun 2015 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0072

What is the output of the following program: (Assume that the appropriate preprocessor directives are included and there is not syntax error)
main( )
    {   char S[]="ABCDEFGH";
        printf("%C", *(&S[3]));
        printf("%s", S+4);
        printf("%u", S);
    /*Base address of S is 1000 */
    }
  1. A
    $\text{ABCDEFGH}1000$
  2. B
    $\text{CDEFGH}1000$
  3. C
    $\text{DDEFGHH}1000$
  4. D
    $\text{DEFGH}1000$

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

Show the worked solutionTake the first format as \%c (the character conversion). \(*(\&S[3])\) is just \(S[3]\), the character D, so the first printf prints D. \(S+4\) points to S[4], so \%s prints the rest of the string: EFGH. \%u prints the address of S, given as 1000. Output: D, then EFGH, then 1000, i.e. DEFGH1000.Answer: D

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