+ 1

String

#include <stdio.h> #include <stdlib.h> #include <string.h> void a(char**strref){ ++strref; } int main() { char *s="hour"; a(&s); puts(s); return 0; } I think the result of the code is “our”,but not. Who can tell me why? 😹

11th Jul 2020, 6:12 AM
Huda Le
Huda Le - avatar
3 ответов
+ 4
You need to change ++strref; to ++*strref; This is because without the * then it’s just changing the value of strref inside the a function, not inside the main function. P.S. Next time, please put the programming language as a tag!
11th Jul 2020, 6:15 AM
Rowsej
Rowsej - avatar
+ 4
No worries!
11th Jul 2020, 6:21 AM
Rowsej
Rowsej - avatar
+ 1
Thanks, Rowsej!
11th Jul 2020, 6:20 AM
Huda Le
Huda Le - avatar