1

would it make any difference if i use c-style functions to search an array or cstring?

3
  • To my understanding an array is similar to string which doesn't have '/0' byte set at the end. Commented Nov 24, 2010 at 14:03
  • 1
    This question is extremely unclear. In C, there is no "string" datatype: all strings are always represented as pointer to NUL-terminated character sequences (arrays). Commented Nov 24, 2010 at 14:05
  • @ unwind I didn't mean std::string in c++. I meant cstring. Commented Nov 24, 2010 at 14:12

3 Answers 3

1

In a character string (cstring), the NULL character at the end acts as a sentinel, to signify the end of the search.

If it's an array of characters without the terminating NULL character, then you had better know the length of the string, to avoid overflow.

Sign up to request clarification or add additional context in comments.

Comments

0

Inside the function it is all the same.

int foo1(char *x) {
    /* x is a (char *) */
}
int foo2(char x[]) {
    /* x is a (char *) */
}
int foo3(char x[42]) {
    /* x is a (char *) */
}

Comments

0

You mean:

char *str1;

and

char str2[ X ];

?

In that case no, it wouldn't do any difference: you need to iterate over all characters of your string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.