Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is the char str a pointer to a char?


Asked by Melvin Ventura on Nov 30, 2021 FAQ



char *str is a pointer to a char (or an array of chars), however, you never assigned it. As has been mentioned earlier a char * basically says "go there" but there is no there there, you never gave it a value.
Likewise,
You called this a "string to a char array", but it's really a pointer to a single char. People often refer to char * as being C's "string type", and in a way it is, but it can be a misleading thing to say, because not every char * is a string, and more importantly C has very few mechanisms for automatically managing strings for you.
Also Know, Using char* Here, str is basically a pointer to the (const)string literal. Only one pointer is required to refer to whole string. That shows this is memory efficient. No need to declare the size of string beforehand. This works fine in C but writing in this form is a bad idea in C++. That’s why compiler shows warning
Just so,
Strings using character pointers Using character pointer strings can be stored in two ways: 1) Read only string in a shared segment. When a string value is directly assigned to a pointer, in most of the compilers, it’s stored in a read-only block (generally in data segment) that is shared among functions.
Also,
So a personality pointer may be a pointer that will point to any location holding character only. Character array is employed to store characters in Contiguous Memory Location. char * and char [] both are wont to access character array, Though functionally both are same, they’re syntactically different.