1. Enter and run the following program. Show the values printed and answer the q
ID: 3906234 • Letter: 1
Question
1. Enter and run the following program. Show the values printed and answer the questions that
follow.
#include<stdio.h>
main(){
int x = 5;
int *ptr_x;
ptr_x = &x;
printf(" The value of x is %d", x);
printf(" The value of *ptr_x is %d", *ptr_x);
printf(" The address of x is %X", &x);
printf(" The value of ptr_x is %X", ptr_x);
printf(" The address of ptr_x is %X”, &ptr_x);
printf(“ The value of ptr_x +1 is %X”, ptr_x+1);
*ptr_x = 10;
printf(“ The new value of x is %i ”, x);
}
What can you say about the value of x and the value of *ptr_x ? ________________
What can you say about the address of x and the value of ptr_x? ________________
What is the new value of x? ___________
How did it get changed?
Explanation / Answer
Output
What can you say about the value of x and the value of *ptr_x ? ______Both are same__________
What can you say about the address of x and the value of ptr_x? _____Both are same___________
What is the new value of x? _____10______
How did it get changed?
ptr_x is pointed to the location where x resides. So, the value of *prt_x is x only.
When value of *ptr_x is changed x is also 10 because ptr_x is referring to location of the x.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.