To print the memory address, you must use %p
. This way:
#include <stdio.h>
int main(void) {
char caractere, *caractere_ptr = &caractere;
printf("Caractere: foi alocado %zu byte\n", sizeof(caractere));
printf("Endereço: %p", caractere_ptr);
}
See running on ideone . And No Coding Ground . Also put it on GitHub for future reference .
I will keep the original answer below for reference because it is still useful to some people, but it is not what the questioner wanted, and what was said is part of an assumption that is now wrong. >
But if you want to make it work correctly you should use %s
.
There is a code table that can be used in a string formatting the printf()
.
In this case you have a character pointer ( char *
) for a character, so it is a string you want to print, so the correct one is %s
. If it were the character there would be %c
. Luckily it will not print anything, but it can print a lot of unwanted stuff because when it prints a string it only for when it encounters a caractere
null character, and it can get a lot of dirt until it finds a null. I speak of this in What's the difference between "NULL", "\ 0" and 0?
Note that what will print is a garbage, since the %code% variable was not initialized.