Home > database >  Why are both conditions wrong?
Why are both conditions wrong?

Time:12-03

I have a problem with my code these 2 conditions aren't True. In fact, I have a Python background and they seem right for me. I hope anyone could help me solving this problem. Thanks for your Time !

    char cArray[12] = "Hello World";

    char* pcVal = &cArray[2];

    if (cArray[2] == "l"){}

    if ((*pcVal) == "l"){}

CodePudding user response:

You are comparing a char with a string literal.

You need to use 'l'

char cArray[12] = "Hello World";

char* pcVal = &cArray[2];

if (cArray[2] == 'l'){}

if ((*pcVal) == 'l'){}
  • Related