The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+14 votes
1.9k views

Consider the following function implemented in C:

void printxy(int x, int y) {
    int *ptr;
    x=0;
    ptr=&x;
    y=*ptr;
    *ptr=1;
    printf(“%d, %d”, x, y);
}

The output of invoking $printxy(1,1)$ is:

  1. $0, 0$
  2. $0, 1$
  3. $1, 0$
  4. $1, 1$
asked in Programming by Active (2k points)
edited by | 1.9k views
0
already solved

9 Answers

+25 votes
Best answer

At first in loop we are giving $x=0$ then $ptr$ is pointing to $X$.

So, $*ptr=0$

Now, we copying the value of $ptr$ to $y$ ,so $Y=0$

 x=0;      //value of x = 0  
    ptr= &x;      // ptr points to variable x
    y= *ptr;      // Y contain value pointed by ptr i.e. x= 0;


Now, value of $ptr$ is changed to $1$. so the location of $X$ itself got modified

 *ptr=1;  

As it is pointing to $x$ so $x$ will also be changed to $1$

So, $1,0$ will be the value

C is correct answer here.

answered by Boss (18.6k points)
edited by
+4 votes
we got x= 1 and y= 1;
void printxy(int x, int y) 
{  
    int *ptr;     //pointer is created which contain integer value.
    x=0;          //value of x = 0 here. 
    ptr= &x;      // ptr point to variable which has 0 
    y= *ptr;      // y contain value pointed by ptr i.e. x= 0;
    *ptr=1;       // value pointer by ptr is now set to 1 i.e. x= 1;
    printf("%d,%d",x,y);  // print x,y = x= 1 y=0

}

C is answer

answered by Veteran (60.8k points)
+3 votes

hope it might help.......

answered by Boss (25.7k points)
+1 vote
C) 1,0
answered by Active (1.6k points)
+1 vote
Option C
answered by Active (2.9k points)
+1 vote
C is the answer
answered by Active (1.2k points)
0 votes

1,0 is the answer

answered by (121 points)
0 votes

answer is C

answered by (191 points)
0 votes

Answer:

Option C: 1,0

 

answered by (49 points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,814 questions
46,793 answers
140,922 comments
58,853 users