C output type question

Q.  C Programming : Find the output

#include< stdio.h>
void i(int *a,int *b)
{
       a=b;
*a=2;      }
int x=0,y=1;
int main()
{
i(&x,&y);
printf(“%d%d\n”,x,y);
return 0;
      }


- Published on 16 Jun 15

a. 22
b. 21
c. 02
d. 01

ANSWER: 02
 
It begins from main I and j globally initialized by 0 and 1. So when we call function i(&x,&y) the address of x and y are passed. When a=b and *a=2 means *b=2, so value of *b is passed 2 and value of *b return to y and value of x and y as 2.
So printf(“%d%d\n”,x,y) give output (0,2)

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)