Question 15Asked in UGC NET Computer Science, June 2015 (Paper II & III, Selected Questions)

What is the output of the following program? (Assume that the appropriate directive are included and there is no syntax error)

What is the output of the following program? (Assume that the appropriate directive are included and there is no syntax error) main () { char S[ ] = "ABCDEFGH", printf ("%C", * (&S[3])); printf ("%s", S + 4); printf ("%u", S); /* Base address of S is 1000*/ }
  1. AABCDEFGH1000
  2. BCDEFGH1000
  3. CDDEFGHH1000
  4. DDEFGH1000
Show answerHide answer

Correct answer: (D) DEFGH1000

Explanation

S occupies addresses 1000 to 1008: A B C D E F G H \0. S[3] is 'D', and *(&S[3]) is 'D' itself, so %c prints D. S + 4 skips 4 characters, so %s prints "EFGH". %u prints the base address of S, 1000. Final output: DEFGH1000.

From UGC NET Computer Science PYQ, June 2015 (Paper II & III, Selected Questions)

This is question 15 of UGC NET Computer Science PYQ, June 2015 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.