Gate2017 ss Q34

0. 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

  • Option : C
  • Explanation :
    void printxy (int x, int y) {
    int *ptr;
    x = 0; // x=0,y=1
    ptr = &x; // x=0,y=1, and ptr points to x
    y = * ptr; //x=0, y=0
    * ptr = 1; //x=1, y=0
    printf (“%d, %d,” x, y); // It prints 1 AND 0.
    }
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *