I am new to programming world. Now I am learning C as my first programming language. I found something strange to understand.
I have learned in C we can represent a String as a sequence of character like this (using char array)-
char status[10] = "Married";
I have learned that the problem of this approach is - we have to tell the size of the status array during compilation.
But now I have learned we can use a char pointer to denote an string like -
char status[10] = "Married";
char *strPtr;
strPtr = status;
I did not understand it properly. My questions are -
1. How can I get char at index 4 (that is i in Married) using the strPtr?
2. In status there is a null character (\0) at the end of the string represented by the char array - M->a->r->r->i->e-d->\0. So by using the null character (\0) we can understand the end of the string. When we use strPtr How can we understand the end of the string?
Thanks in Advance.
Aucun commentaire:
Enregistrer un commentaire