+ 16

Why output is "ouch" ?

I don't know why a==b is true. https://code.sololearn.com/cx5qt0lux4pF/?ref=app

22nd Mar 2019, 8:16 PM
Pedro H.J
Pedro H.J - avatar
8 Answers
+ 12
Let's elaborate it a bit : When we decade a string on this manner : char* word = "World without L"; // Now that string is an array of characters and every single element can be accessed in this way : first : *word second : *(word + 1) third : *(word + 2) And so on, every time we add a number it increments the address but when you simple use : word, it will display the entire word(unless you increment it permanently using pre and post increment) In the above example we are checking the equality of just the first character, so the output is ouch.
23rd Mar 2019, 7:46 AM
RZK 022
RZK 022 - avatar
+ 13
Both *a and *b are 'c' (first char of char array), so they're equal
22nd Mar 2019, 8:50 PM
Anna
Anna - avatar
+ 11
Use "if (a==b)" to get "awesome"
23rd Mar 2019, 2:31 AM
Sonic
Sonic - avatar
+ 9
Makes sense. Thank you so much.
22nd Mar 2019, 8:52 PM
Pedro H.J
Pedro H.J - avatar
+ 3
its simply because the adresses pointed have the same datatype char
24th Mar 2019, 6:19 AM
Jeremiah Ndegwa
Jeremiah Ndegwa - avatar
23rd Mar 2019, 1:38 PM
Nitin Madas
Nitin Madas - avatar
+ 1
makes sense
24th Mar 2019, 12:40 AM
seth eslami
seth eslami - avatar
+ 1
Because a and b are char so they consider only c as initial value so they are equal
5th Apr 2019, 9:26 AM
Patel Bimal
Patel Bimal - avatar