Which of the following is an example of passing a pointer to a function in C?

19 views
  • int x = 5; foo(x);
  • int x = 5; foo(&x); (Correct Answer)
  • int x = 5; foo(*x);
  • int x = 5; foo(&&x);

Explanation

Correct answer: b) int x = 5; foo(&x);

Explanation: When we want to pass a pointer to a function in C, we use the & operator to get the address of the variable, and then pass the pointer to the function. In this case, &x is the address of the variable x, which is passed to the function foo.

Comments (0)

No comments yet. Be the first to comment!

Want to practice more?

Explore thousands of MCQs across every exam category on Exams Nepal.

Find More MCQs