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 */
}
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development