Question
#include void funct1 ( int p1, int *p2); int main() { int x = 5; int *y; printf (Hello World ); y = &x; printf
#include
void funct1 (int p1, int *p2);
int main()
{
int x = 5;
int *y;
printf ("Hello World ");
y = &x;
printf ("Print line 1: %d ", x);
printf ("Print line 2: %p ", &x);
printf ("Print line 3: %p ", y);
printf ("Print line 4: %p ", &y);
printf ("Print line 5: %d ", *y);
/* printf ("Print line 6: %d ", *x); */
int a = 2;
int b = 4;
printf ("Print line 11: For variable a: value: %d, address: %p ", a, &a);
printf ("Print line 12: For variable b: value: %d, address: %p ", b, &b);
funct1 (a, &b);
printf ("Print line 13: For variable a: value: %d, address: %p ", a, &a);
printf ("Print line 14: For variable b: value: %d, address: %p ", b, &b);
}
void funct1 (int p1, int *p2)
{
printf ("Print line 101: %d ", p1);
printf ("Print line 102: %p ", &p1);
printf ("Print line 103: %p ", p2);
printf ("Print line 104: %p ", &p2);
printf ("Print line 105: %d ", *p2);
p1 = p1 + 5;
*p2 = *p2 + 5;
}
Understanding the difference between the unary * and unary & operators is a truly important skill in C The * operator has many meanings. It mean multiplication when used as a binary operator (7 * 8), but does "address dereferencing" when used as unary operator. When used in a variable/parameter declaration statement, it means the variable/parameter will store an address location. Consider the following code (from labla.c): int x- 5; int *y; printf ("Print line 1: %din", x); printf ("Print line 2: %pm", &x); printf ("Print line 3: 90pm", y); printf ("Print line 4: %pm", &y); printf ("Print line 5: %din", *y); la. What type of variable is x? What value is stored in x? lb.What type of variable is y? What value is stored in y? 2. Will all the above printf) statements always display the same results? Why or why not? L.E. If I ran the above code multiple times on the same or different machines, will I always get the same output?) 3.What would happen if you could to include the following line to the above program? Why? printf ("Print line 6: %din", *x); In C, we use & and * to simulate pass-by-reference parameters. A pass-by-reference parameter that is changed in a function will reflect that modification at the calling code. Assume we have the function void functl (int pl, int *p2) printf ("Print line 101 : %dn", p 1); printf("Print line 102: %pin'', &p1); printf ("Print line 103: %pm", p2); printf ("Print line 104: %pin", &p2); printf("Print line 105: %dm", *p2); pl-pl+S; p2 *p2 +5 Which is called by the following code in main int a- 2 int b-4; printf ("Print line l 1: For variable a: value: %d, address: %pm", a, &a); printf ("Print line 12: For variable b: value: %d, address: %pm", b, &b); functl (a, &b); printf ("Print line 13: For variable a: value: %d, address: %pin", a, &a); printf ("Print line 14: For variable b: value: %d, address: %pm", b, &b); Do the values associated with variables a and b change because of the call to functl()? Why? 5.Does the address information from Print line 11 through 14 match to any information printed in Print line 101 through 105? If so, describe all the address information that matches between the two sets of Print line statements
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started