Which of the following is the correct output for the ‘C’ program given below:

#include<stdio.h>
void afun(char *) ;

int main( )        
{
char ch[10] ;
ch[0] = 'X' ; ch[1] = 'Y' ; ch[2] = 'Z' ;
ch[3] = 'Z' ;
afun (& ch[0]) ;
return 0 ;
}

void afun (char *c)
{
c++ ;
printf("%c", *c) ;
c++ ;
printf("%c\n", *c) ;
}

Correct output is:

This question was previously asked in
UGC NET Paper 2: Electronic Science July 2018 Official Paper
View all UGC NET Papers >
  1. XY
  2. YZ
  3. ZW
  4. None of the above

Answer (Detailed Solution Below)

Option 2 : YZ
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
10.8 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Assume

Decimal address

100

101

102

103

104

105

106

107

108

109

character array

ch[0]

ch[1]

ch[2]

ch[3]

ch[4]

ch[5]

ch[6]

ch[7]

ch[8]

ch[9]

corresponding value

X

Y

Z

Z

\0

 

 

 

 

 

 

&ch[0] → gives that address of first element

int *c = 100

c++  \\ c = c + 1 = 100 + 1 = 101

printf(“%c”,*c) \\ dereferencing the value at location 101

output = Y

c++  \\ c = c + 1 = 101 + 1 = 102

printf(“%c”,*c) \\ dereferencing the value at location 102

output = Z

Final Output: YZ

Latest UGC NET Updates

Last updated on Jun 12, 2025

-> The UGC NET June 2025 exam will be conducted from 25th to 29th June 2025.

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

More Call By Reference Questions

Get Free Access Now
Hot Links: teen patti master purana teen patti master plus teen patti rummy 51 bonus