Machine-translated by Google. Questions are authored in English.
Top

Discussion

In the following program add a statement in the function fun() such that address of a gets stored in j?

#include <stdio.h>
int main()
{
    int *j;
    void fun(int**);
    fun(&j);
    return 0;
}
void fun(int **k)
{
    int a=10;
    /* Add a statement here */
}

 

  • A.**k=a;
  • B.k=&a;
  • C.*k=&a
  • D.&k=*a

Answer: C

Correct answer: *k=&a

fun receives &j, so k points to the caller's pointer j. Writing through it - *k = &a - stores the address of a into j itself, which is what the question asks for.

The alternatives fail at different levels: k = &a changes only the local parameter, **k = a assigns a value rather than an address, and &k = *a is not valid syntax. Note that a is local to fun, so the address stored dangles once the function returns.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.