recategorized by
9,552 views
30 votes
30 votes

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$
recategorized by

11 Answers

0 votes
0 votes

Explanatin:

initially x and y are passed into this function using call by value printxy(1,1)

X is 1 

y is 1

now what you are doing is assigning x=0 

 

now x=0 y=1

PTR is pointing to x means it has x’s address

x’s value is now copied into y

x=0 and y=0

*ptr=1 means you are assigning value 1 to x

now x=1, y=0

Option C

Answer:

Related questions

70 votes
70 votes
13 answers
1
Madhav asked Feb 14, 2017
27,486 views
Consider the following C program.#include<stdio.h #include<string.h int main() { char* c="GATECSIT2017"; char* p=c; printf("%d", (int)strlen(c+2[p]-6[p]-1)); return 0; }T...
25 votes
25 votes
7 answers
3
Madhav asked Feb 14, 2017
11,775 views
Consider the following C program.#include<stdio.h int main () { int m=10; int n, n1; n=++m; n1=m++; n ; n1; n-=n1; printf(“%d”, n); return 0; }The output of the prog...
26 votes
26 votes
3 answers
4
khushtak asked Feb 14, 2017
5,771 views
Match the following:$$\begin{array}{|ll|ll|}\hline P. & \text{static char var ;} & \text{i.} & \text{Sequence of memory locations to store addresses} \\\hline Q. & \text...