47 47 votes The value printed by the following program is _______. void f (int * p, int m) { m = m + 5; *p = *p + m; return; } void main () { int i=5, j=10; f (&i, j); printf ("%d", i+j); } Programming in C gatecse-2016-set2 programming-in-c normal numerical-answers parameter-passing + – Akash Kanase 14.3k views answer comment Share Follow Print See 1 comment 1 1 comment reply nirmal_aravind commented Oct 5, 2025 reply Follow flag Game of Passing by value, passing by reference using pointers same type of question asked 2016 set 1 question 15 0 0 replyShare Please log in or register to add a comment.
Best answer 66 66 votes $i$ is called by reference and $j$ is called by value. So, in function $f()$ only value of $i$ might change, Now, in function $f(*p,m)$ $*p$ is pointing to $i$ Thus $*p$ is $5$. $m$ is $10$ because of call by value of $j$. $m=10+5$ hence $m=15$ $*p=5 + 15$ hence $*p=20$, that is, value of variable $i$ is now $20$ returns nothing Now, back to main $i=20$ and $j$ is as it is $10$ Hence, output of printf will be $i+j=20+10 = 30.$ Shashank Chavan answered Feb 12, 2016 • edited Jun 15, 2018 by Milicevic3306 Shashank Chavan comment Share Follow 0 reply Please log in or register to add a comment.
10 10 votes void f(int * p, int m) { // function call come here with parameter p is pointer contain i's address and m is memory location created for m and contain j value) (4) m = m + 5; // m value increment by 5 i.e. m= 10 + 5= 15 (5) *p = *p + m; // p contain address of i and *p point value at i's address so increment that by m i.e. *p = 5 + 15 =20 now *p point i which contain 20 (6) return; // return control to main program (7) } void main () { // start from here (1) int i=5, j=10; // memory created for i and j with value 5, 10 store in it (2) f (&i, j); // function call (address of i and value of j as parameter) (3) printf ("%d", i+j); // since i value changed during call by reference print 20 + 10 = 30 (8) } Prashant. answered Aug 5, 2016 • edited Dec 8, 2017 by Puja Mishra Prashant. comment Share Follow 0 reply Please log in or register to add a comment.
10 10 votes .... Hira Thakur answered Oct 30, 2017 Hira Thakur comment Share Follow See 1 comment 1 1 comment reply go_rajesh commented Jan 14, 2025 reply Follow flag Great Explaination. 0 0 replyShare Please log in or register to add a comment.
5 5 votes Concept:- Call by reference & Call by value Call by reference:- The change in argument value in called function(f) reflected into calee function(main). Call by value:- Doesn't Reflect Here variable i is Called by reference with original Value 5 then it changed to 20 By statement *p=*p+m where *p is Value at p means i and argument j is passed by Value so it's change in called function (f)not reflected to calee function (main). So Finally Ans is i+j= 20+10=30 Rajesh Pradhan answered Aug 6, 2016 Rajesh Pradhan comment Share Follow See 1 comment 1 1 comment reply pkrai1993 commented Jan 27, 2018 reply Follow flag https://gateoverflow.in/39642/gate-2016-1-15. In this question, Answer was calculated by ignoring Call By Reference. Here we are taking call by reference. When to decide whether call by reference should be taken or not? 0 0 replyShare Please log in or register to add a comment.
0 0 votes just start from void main and follow below:- Shivam Patidar answered Jul 15, 2018 Shivam Patidar comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes P is a pointer stores the address of i, & m is the formal parameter of j. Now, m = m + 5; *p = *p + m; Hence, i + j will be 20 + 10 = 30. varunrajarathnam answered Dec 14, 2020 varunrajarathnam comment Share Follow 0 reply Please log in or register to add a comment.