0

pointer

#include <iostream> using namespace std; void cpy(char*, const char*); int main() { const char* s = "ABCDEFG"; char* ss = "ZZZZZZZZZZ"; cout << " s = [" << s << "], ss = [" << ss << "]\n"; cpy(ss,s); cout << " s = [" << s << "], ss = [" << ss << "]\n"; } void cpy(char* s1, const char* s2) { do *s1++ = *s2++; while (*s2); } not returning the copied version

26th Apr 2021, 10:29 AM
Ramisa Fariha
Ramisa Fariha - avatar
9 odpowiedzi
+ 1
@Martin Thanks a lot
26th Apr 2021, 5:27 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
the question was Write the following function that copies the first n bytes beginning with *s2 into the bytes beginning with *s1, where n is the number of bytes that s2 has to be incremented before it points to the null character '\0': void cpy(char* s1,const char* s2)
26th Apr 2021, 10:34 AM
Ramisa Fariha
Ramisa Fariha - avatar
0
@Martin That's for string but what if I want to do this using pointer? Like using this function..why it's not working
26th Apr 2021, 12:10 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
https://code.sololearn.com/c3A21A17A18A the code runs but after calling the function the copied string do not show in the output,why is that? and also another thing like really confuses me in pointer that is when to use a function like int* something and just int like what is the difference? like for example between int* addition() and int addition(). and the question no was 7.9
26th Apr 2021, 4:03 PM
Ramisa Fariha
Ramisa Fariha - avatar