Assign Array to String Literal

Is this undefined behavior for this?

char *a = "hello";
char b[] = "abcd";
a = b;

My compiler does not generate warnings with a maximum warning level.

+4
source share
1 answer

There is no UB. You simply reassign the pointer to point to the start address of the array.

Please note that you do not actually change the value that it points to a, only a, but ais normal char *.

+10
source

Source: https://habr.com/ru/post/1665046/


All Articles