Sto imparando a programmare in C e uso Xcode del mio mac. Ho provato a scrivere un programma, preso dal libro di programmazione, che intende dimostrare la complementarietà degli operatori per i puntatori (& e *).
Il problema che riscontro è l'output.
Il mio output è :
Perché efbff5fc e 0x7ffeefbff5fc ??????
Il libro dice che l'output è :
Come posso risolvere? Se può servire, le impostazioni di Xcode sono
Default text encoding: Unicode (UTF-8)
Default line endings: macOS / Unix (LF)
C:
#include <stdio.h>
int main(void)
{
int a = 7;
int *aPtr = &a;
printf("The address of a is %x"
"\nThe value of aPtr is %x\n", &a, aPtr);
printf("\n\nThe value of a is %d"
"\nThe value of *aPtr is %d", a, *aPtr);
printf("\n\nShowing that * and & are complements of "
"each other\n&*aPtr = %p"
"\n*&aPtr = %p\n", &*aPtr, *&aPtr);
}
Il problema che riscontro è l'output.
Il mio output è :
The address of a is efbff5fc
The value of aPtr is efbff5fc
The value of a is 7
The value of *aPtr is 7
Showing that * and & are complements of each other
&*aPtr = 0x7ffeefbff5fc
*&aPtr = 0x7ffeefbff5fc
Perché efbff5fc e 0x7ffeefbff5fc ??????
Il libro dice che l'output è :
The address of a is 0028FEC0
The value of aPtr is 0028FEC0
The value of a is 7
The value of *aPtr is 7
Showing that * and & are complements of each other
&*aPtr = 0028FEC0
*&aPtr = 0028FEC0
Come posso risolvere? Se può servire, le impostazioni di Xcode sono
Default text encoding: Unicode (UTF-8)
Default line endings: macOS / Unix (LF)