This is C source code... not c++
#include <stdio.h>
int x;
int *xpos;
x = 13;
xpos = &x;
printf("%i\n",x);
printf("%p\n\n",xpos);
Printable View
This is C source code... not c++
#include <stdio.h>
int x;
int *xpos;
x = 13;
xpos = &x;
printf("%i\n",x);
printf("%p\n\n",xpos);
um what are i and n and why do you need a pointer
I need a pointer because I am learning C and want to learn how to use them. I want to declare a variable... make a pointer variable point to it, and then print the original variable and the memory location of that variable... aka the pointer.
don't use stdio.h usiostream just because i say so and i don't like stdio
Code:#include <iostream.h>
int main(){
int i = 27;
int *pi = &i;
cout<<"i="<<i<<"\n";
cout<<"&pi="<<&pi<<"\n";
return 0;
}
He specifically said C, so <iostream.h> is out. Even with C++, it is recommended that you use <iostream>, the newer header file.
Anyway, try changing the %p to a %i. It should print out the decimal value of the pointer.
Z.
Magiaus: the %i means print an integer, the \n is a newline.
zer0_flaw: Do you have a main function in your app?
yhanks bee man i new what the newline escape char was after i looked at his code closer i just wasn't familer with the 96i
plus i don't know straight c so.... i guess i shouldn't answer questions unless i know what i'm talking about
My bad side just won my internal discussion whether I should post to state that I won't comment on that or not.
Whatever...
ater debating i decided to post and say cornedbee is the man