lundi 22 août 2016

Typecasting character pointer to an integer pointer

#include <stdio.h>
int main()
{
    int a[3]={2,3,4};
    char *p=a;
    printf("%d ",*p);

    p=(int *)(p+1);//What does this statement do ?
    printf("%d",*p); //Will the pointer extract 2 bytes(16 bit compiler)or1?  

    return 0;
}

I'm getting output as 2 0 . I understood why the first printf is printing 2 but not understanding why 0 in the next printf ? Is it that if I want to jump so many bytes away then I should a pointer of that many bytes long ?

Aucun commentaire:

Enregistrer un commentaire