Pointers problem

This is what I made but I cant make it do what I want
"Use pointer dereferencing on pointers to y and z to change the value of
variables y = 10, z = x."

How can I make this work? it just comes out as the address of the pointer...


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

int x, y, z;
int *p1, *p2, *p3;

p1= &x;
p2= &y;
p3= &z;

*p1= *p3;
*p2= 10;
*p3= x;

printf("\n y is equal to %d \n"),y;
printf("\n z is equal to %d \n"),x;

system("pause");
return 0;
}
Your printf function is set up incorrectly, it should be.
printf("\n y is equal to %d \n",y);

Also x is going to print out an undefined number as it was never actually given a value.
how can i make x =z? thats the real prob i have
http://kontaktniy.orgYour printf function is set up incorrectly, it should be.
printf("\n y is equal to %d \n",y);

thanks a lot!
Last edited on
it actually works in c++:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cstdio>
#include <cstdlib>

int main(int argc, char *argv[])
{

int x = 1, y = 2, z = 3;
int *p1, *p2, *p3;

p1= &x;
p2= &y;
p3= &z;

*p1= *p3;
*p2= 10;
*p3= x;

printf("x=%d, y=%d, z=%d\n",x,y,z);

//system("pause"); //???
return 0;
}
Topic archived. No new replies allowed.