"So umm, to reverse a string...you umm, first you cre-"

>"So umm, to reverse a string...you umm, first you cre-"
>"You don't know what you're talking about, do you?"

Attached: problem.jpg (960x640, 50.54K)

Interviews are bullshit anyway. I'm a cloud dev and all I do is API design patterns and code review.
I don't *write* code.

C has no strings, retard

myString.reverse()

based kotlin dev

You have a cloud brain too.

I get paid more than people who make planes fly and banks work. Sit down and keep your head down.

,[>,]

>well you first create a null pointer then allocate memory on that pointer for the length of the string, then do memcpy from the last character into a pointer of const char and use a for loop for free already read characters and turn it into a reference

Attached: 165723866123521.jpg (1024x768, 569.56K)

Strlen is O(n), and you made a off by one error.

in-place or copying?

Hm? Oh, thanks we'll call you. Don't call us.

In what languages are strings not character arrays? C isn't special.

please another chance.

That doesn’t reverse a string, that outputs the string in reverse

char *str_reverse_in_place(char *str, int len)
{
char *p1 = str;
char *p2 = str + len - 1;

while (p1 < p2) {
char tmp = *p1;
*p1++ = *p2;
*p2-- = tmp;
}

return str;
}

>umm yes I would like to reverse this string
>do you happen to know its lenght?
>excuse me? I already gave you the string, why can't you calculate it yourself

use unicode_segmentation::UnicodeSegmentation;

fn reverse_string(string: &str) -> String {
let mut out = String::with_capacity(string.len());
for grapheme in string.graphemes(true).rev() {
out.push_str(grapheme);
}
out
}

In every sane language, length is stored alongside the string pointer.

Based. Nobody in this thread even mentioned encoding. Only right answer.

void reverse_inplace(char *str) {
const int length = strlen(str);
for (int i = 0; i < length/2; i++) {
str[i] = str[length - i - 1];
}
}

char *reverse(const char *str) {
const int length = strlen(str);
char *result = (char*) calloc(length, sizeof(char));
for (int i = 0; i < length; i++) {
result[i] = str[length - i - 1];
}
return result;
}

std::string reverse_cpp(const std::string& s) {
std::string result;
std::copy(s.rbegin(), s.rend(), std::back_inserter(result));
return result;
}

Use whichever you want nigga

>in_place
>doesn't return void

Oh fuck the first function should have swapped the two chars. Sorry guys I failed the interview

So this is the power of C++...

Attached: file.png (440x137, 9.78K)

Null or an address that isn't reachable would imply an error occurred

string.split("").reverse().join("");

not him but id do this but to a new char[] of same length and put the chars there with the for loop