A
Do not use conio.h, even if in this case you don't even need to. And if there is a bad compiler IDE (Dev-C++), stop doing this. Alias the Code::Blocks does nothing in running the same code, https://pt.stackoverflow.com/q/101691/101 .From what I understand the first you want to print the address of memory where is the X already used %p, and the second wants to print the value of X. Then you have to sort out the text to give correct information.There's a problem that's inverted. p It is already a memory address, so just use it on the first. The second wants the value and take it indirectly by the variable p which is an address, so now you have to do the reverse operation you had done to get the address X, then you have to do what is called melting, which is done with the operator *. O *P means "take the value that is in the address of p".I put one (void *) because good compilers with the correct configuration prevents the direct build, they force you to be explicit in what is using to indicate that it is not confusing what is sending. But it is possible not to use in certain circumstances (I did not use in the Coding Ground, look there), at the risk of doing something wrong in more complex real code.#include <stdio.h>
int main() {
int x = 2;
int *p = &x;
printf("O endereço de X e: %p\n", (void *)p);
printf("O valor de X e: %d\n", *p);
}
See https://ideone.com/i6sMDw . And https://repl.it/join/fqkfxopx-maniero . Also https://github.com/maniero/SOpt/blob/master/C/Pointer/PrintPointer.c .See more in https://pt.stackoverflow.com/q/125793/101 and https://pt.stackoverflow.com/q/156278/101 .