0

C++ POINTERS

#include <iostream> using namespace std; int main() { char st[20]; char st2[20]; char* p, * j; cout << "enter a string:"; cin >> st; p = &st[0]; j = &st2[0]; do { *j = *p; p++; j++; } while (*p != '\0'); *j = '\0'; cout << st2; } HOW DOES IN THIS CODE 'st2' prints the string that the user insert , bcz I didn write that st = st2; HOW IS THAT POSSIBLE? CAN ANYONE HELP ME

20th Dec 2020, 11:00 PM
Hammad Yaqub
Hammad Yaqub - avatar
1 Resposta
+ 4
Because of this .." *j = *p; " ..and " j " is a pointer to str2.
20th Dec 2020, 11:21 PM
rodwynnejones
rodwynnejones - avatar