961 views
1 1 vote

My Query is as it is passing by reference so a in M actually refer to location b.So a=a*a=169 will be updated as b.Then how can b be 13?

Please anyone rectify me.

2 Answers

3 3 votes
There is no variable declaration in main. So, b in main refers to global b and is initialized to 12.

In N also no declaration of b. So, it updates the global b to 13.

The reference of the global b is passed to M and M updates it to 169.

So, output a = 169, b = 169.
1 1 vote

Answer is : a] 

Static scoping : https://courses.cs.washington.edu/courses/cse341/03wi/imperative/scoping.html

Now,

if parameters are passed by values,

    a= 169 and b =13

and if parameters are passed by reference,

   a = 169 and b = 169

Big bros' advice : "Move forward.."

• edited by
Position:
Show:

Related questions

0 0 votes
0 0 answers
386
386 views
SAUMYA2019 asked Jan 24, 2019
386 views
in the soln how they are taking i?
1 1 vote
1 1 answer
374
374 views
Depinder asked Jul 6, 2025
374 views
#include <stdio.h>struct Point { int x; int y;};int main() { struct Point p = {10, 20}; struct Point *ptr = &p; printf("%d %d", ptr->x, (*ptr).y); retur...
0 0 votes
2 2 answers
744
744 views
Sourin Kundu asked Jan 23, 2023
744 views
How many number of add and remove operations are required to access 26th element of a queue of 50 elements,so that the original queue remains the same after the access is...
0 0 votes
2 answers 2 answers
805
805 views
Overflow04 asked Oct 2, 2022
805 views
#include <stdio.h int main(){ int a[] = {5,3,7,2,4}; int *p = &a[3]; p -= *p; printf("%d ",*p); return 0; } output is 3.Why 2 * sizeof(int) is doene.?