Question: 1 . Consider the following ( erroneous ) program in C: void p ( ) { int y; printf ( % d ,

1. Consider the following (erroneous) program in C:
void p (){ int y; printf ("%d ", y);
y =2; }
void main ()
{ p(); p();
}
Although the local variable y is not initialized before being used, the program prints two values the first value typically is garbage (or possibly 0, if you are executing inside a debugger or other controlled environment), but the second value might be 2(try this on Unix!).
(a)(12 pts) Explain this behavior. Why does the local variable y appear to retain its value from one call to the next?
(b)(12 pts) Explain in what circumstances (without modifying function p) the local variable y will not retain its value between calls, and show an example.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!