Why output is "ouch" ?

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

3/22/2019 8:16:56 PM

Pedro H.J

8 Answers

New Answer


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.


Both *a and *b are 'c' (first char of char array), so they're equal


Use "if (a==b)" to get "awesome"


Makes sense. Thank you so much.


its simply because the adresses pointed have the same datatype char


Beacuse https://code.sololearn.com/c02SExhee290/?ref=app


makes sense


Because a and b are char so they consider only c as initial value so they are equal