Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C, pointers, basic problem

Name: Anonymous 2006-05-20 14:45

Here is my code, just learning more about pointers:
include<stdio.h>
main()
 {
int x, *ptr_x;
int y, *ptr_y;
int z, *ptr_z;
x=64;
y=128;
z=256;
puts("This is a program used to display information on pointers:\n");
printf("x=%d and the pointer is %p\ny=%d and the pointer is %p\nz=%d and the pointer is %p\n",x,y,z,ptr_x,ptr_y,ptr_z);
return 0;
 }

And the output:
This is a program used to display information on pointers:

x=64 and the pointer is 0x80
y=256 and the pointer is 0x8fe07604
z=0 and the pointer is 0x1

Name: Anonymous 2006-05-20 14:51

and the problem is? why do people always post a bunch of statements, and then look for an answer to some 'question' they never asked?

i assume your 'problem' is the fact that the output looks wrong. it's not tho. the order of your variables in the printf string is 'x, x_ptr, y, y_prt, z, z_prt', but the order of the parameters in the printf is 'x, y, z, x_ptr, y_ptr, z_ptr'. obviously, the order of the parameters should match the order of their appearence in the string you're printing.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List