What is the output of the following C program?
[gamipress_button type=”submit” label=”Run Code Online” onclick=”window.open(‘https://coderseditor.com’,’_blank’)”]
void fun(int *p) { static int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); printf("%d", *p); getchar(); return 0; }
Studently Answered question October 10, 2022
Output: 20
q is a duplicate of the pointer p inside of fun(). As a result, if we change q to point at another object, p is unaffected.
Studently Answered question October 10, 2022