What are the specifics of the definition of a string in C?

quango :

I am supposed to answer a homework question for one of my classes. Specifically, I am supposed to say if certain arrays in C are considered strings or not. Based on this article (https://www.geeksforgeeks.org/strings-in-c-2/) I know that strings are an array of characters with the null terminator at the end.

My main hangup is a part of the question that asks about an array that looks like this:

char c1[] = { 'C', 'S', '\0', '3', '2', '4', '\0' };

This is obviously an array of characters with a null terminating character at the end. However, is it still considered a string since it also has a null terminating character in the middle? How will that affect the string?

EDIT: Based on comments, I have provided the actual wording of the question:

"Which of the following arrays can be considered "strings" for the purposes of using them as arguments to strcpy(), strncpy(), strcmp(), strncmp(), and similar string functions (indicate all the apply)?"

EDIT: I emailed my professor about it since the question seemed ambiguously worded (as several people pointed out). If anyone is curious, he told me "Yes it is a string. The key is that there is a null character. But of course that will effect any string operations; the string ends at the null character."

DevSolar :

c1 is mostly [1] equivalent to &c1[0], which is holding one string, "CS".

There's a second string lurking in there, "324", starting at &c1[3] -- but as long as you access c1 as c1, the string "CS" is all the functions strcpy() et al. would see.


[1]: c1 is an array, &c1[0] is a pointer.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29533&siteId=1