Correct me if I am wrong but the notation "C string" refers to a pointer that points to 3 or more bytes in memory, while the 3rd one is NULL.
Pointer must be at least 4 bytes in memory (since the address value they represent is similar to the integer, which is most likely stored in 4 bytes). Which means one pointer can point to an offset address without overflow, while according to the data type, n number of bytes will be readed. If it is char it is only the offset address to be readed. So if we allocate 6 bytes to int* we can have up to 2 characters without oferflow.
If the above said and rephrased by me is correct. Then:
int* str = calloc(sizeof(int), 2);
is a string that can contain up to 4 characters. If we want to treat bytes separately we can use type-casting. Type-casting to ignore the warnings as well. Everything other then that, seems exactly like a string. Where am I wrong?
Aucun commentaire:
Enregistrer un commentaire