+ 1

Explain this for me

So I was on brainly the other day. Somebody wanted this code explained: if(*str1 && *str1 == str2) { str1++; str2++; } I don't exactly remember the meat of the code, as it wasn't important. Was pretty much as you see. I do however, remember the if statement. Is the asterisk just part of the var name? Why would they be comparing one variable as if it were 2? What language even is this? I also don't remember if there was an asterisk before str2. But can somebody help me understand this?

28th Sep 2018, 7:55 AM
Daniel Cooper
Daniel Cooper - avatar
1 Answer
0
If this is C++, str1 is a pointer (type unknown) and the asterisk is used to dereference the address str1 holds. Rough translation: If the dereferenced value of str1 is not falsey and the value of str1 is equal to str2, increment str1 address (assuming str1 is a pointer to an array) then increment str2 value (assuming str2 is of integral type).
28th Sep 2018, 8:11 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar