(1), is this an undefined behavior for string literal ?
This declaration
char *str1 = "string 1"; // (1)
is a valid declaration of a pointer to a string literal in C. Opposite to C++ in C string literals have types of non-constant character arrays.
However string literals are immutable in C as in C++. You may not change a string literal. Any attempt to change a string literal results in undefined behavior.
From the C Standard (6.4.5 String literals)
7 It is unspecified whether these arrays are distinct provided their
elements have the appropriate values. If the program attempts to
modify such an array, the behavior is undefined.
It is preferable to declare pointers to string literals as it is required in C++ that is like
const char *str2 = "string 2"; // (2)
This makes your program more safer because the compiler will issue an error if you will try to pass a pointer to a string literal to a function the corresponding parameter of which is a pointer to non-constant char.