c - Difference between int*a and char *a? -



c - Difference between int*a and char *a? -

what difference between char *a , int *a both work on code blocks storing character pointer eg.

char *c, k = '$'; int *j; j = &k; printf("%c\n%p\n%c\n", k, j, *j); c = &k; printf("%c\n%p\n%c", k, c, *c);

activate diagnostics , don't ignore them (-wall -wextra -pedantic-errors). compiler should tell you doing disallowed.

see here on coliru: http://coliru.stacked-crooked.com/a/31acb5b670254167

main.cpp:7:7: error: incompatible pointer types assigning 'int *' 'char *' [-werror,-wincompatible-pointer-types] j = &k; ^ ~~

answering question, char integer-type of lower rank int (meaning potentially (and in practice guaranteed) smaller size , value-range), , pointers either different types too. using pointer of wrong type access object (with few exceptions) ub.

c pointers

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -