PROBLEMA Xcode non mi stampa i valori in esadecimale

pongo18

Nuovo Utente
8
1
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 *).
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)
 

Andretti60

Utente Èlite
6,440
5,091
Non c'è nulla di sbagliato.
I formati x e p interpretano e stampano i valori in modo diverso. Il formato x prende il valore come un intero e lo stampa in formato hex, mentre il formato p interpreta il valore come un puntatore di memoria, che dipende dal sistema operativo e dalla CPU che si usa.
Probabilmente l’esempio che hai è parecchio vecchio (i puntatori moderni adesso sono numeri giganteschi)
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!

Discussioni Simili