I always thought that an expression like const int *a means a is an int pointer to const , and as such should not change the value it points to. Indeed, if you do const int a [] = {1,2,3} and then issue a[0] = 10 , you will get compiler errors.
To my surprise, however, the following compilations are without any warning and work very well.
#include <stdio.h>
Why is this allowed? Is it related to cast? When I do memcpy(&a[0], (const void*)&b[0], 3*sizeof(int)); , the compiler immediately generates the following warning:
cpy.c: In function 'main': cpy.c:9:3: warning: passing argument 1 of 'memcpy' discards 'const' qualifier from pointer target type [enabled by default] /usr/include/string.h:44:14: note: expected 'void * __restrict__' but argument is of type 'const int *'
source share