0

Something about variables , pointers and Asterisk in declaration

What happen when i write char *str1 = "hello!"; Why does it create an array str1[] automatically? Is *str1 a pointer? If so why does *str1 points to the first element of the array str1 ? Is pointers of the rest of the elements created ? https://code.sololearn.com/cJ8IQevzq99P/?ref=app

22nd Nov 2018, 10:34 AM
Barry Chen
Barry Chen - avatar
1 Answer
+ 3
In C++, arrays and pointers are interchangable. The programmer is responsible for making sure you don't access beyond the allocated memory. There is a single variable str1. It can be used as either a pointer or array.
24th Nov 2018, 4:02 AM
John Wells
John Wells - avatar