if("abc"=="abc") printf("Equal strings"); else printf("Unequal strings"); output: Equal strings explanation: - In this case, both "abc" are string literals. - String literals with the same contents might be stored at the same memory location by the compiler, depending on the implementation. - Therefore, the comparison "abc" == "abc" can be true because both literals might point to the same address in memory. - Thus, the output is Equal strings. char x[4] = "abc"; //used size [4] to include null terminator char y[4] = "abc"; if(x==y) printf("equal strings"); else printf("unequal strings"); output: unequal strings explanation: -Here, x and y are character arrays, not string literals. - Each array x and y will have its own separate memory location. - When you use the == operator on arrays, you are comparing their addresses, not their contents. - Since x and y are different arrays, their addresses will not be the same. - Therefore, the comparison x == y is false, and the output is Unequal strings. right approach to compare strings: #include #include int main() { char x[4] = "abc"; // Note: x[4] to include the null terminator '\0' char y[4] = "abc"; // Note: y[4] to include the null terminator '\0' if(strcmp(x, y) == 0) printf("Equal strings"); else printf("Unequal strings"); return 0; }
@aryushgupta86805 ай бұрын
Thanks buddy!!
@GateCse-20253 ай бұрын
thanks chatgpt.
@satyaprakashsingh9523 жыл бұрын
I have learing your all pointer video sir Too good explained by you
@sammanluitel30183 жыл бұрын
Please make complete c tutorial please with many examples of coding problems using D's algo aswell
@AmitKhuranaSir3 жыл бұрын
I will make playlist on C language soon.....
@atultripathi522 жыл бұрын
sir you are wrong at 2.25 "abc"=="abc" returns 1
@guru_cse Жыл бұрын
It is compiler dependent.
@dherendrasingh4761 Жыл бұрын
right , me also check on online gdb, getting true condition result
@dherendrasingh4761 Жыл бұрын
Sir, i check ABC==ABC concept by program but I found true condition result . How ABC is different from ABC ? #include int main() { char x[5] ="ABCD"; printf("%s ",x); if("ABC" == "ABC") printf("HELLO "); else printf("BYE "); return 0; } O/P ABCD HELLO
@rndmdpe237 ай бұрын
same happened with me as well, if you do printf("%u %u","string","string"); how many times you want, you ge tthe same address. maybe for same strings the same one created in the memory is used(like in JAVA). but if we would've done like char a[]="ok', b[]="ok". then if(a==b) would result in false. this was all i could understand i hope it helps also correct me if i'm wrong
@atultripathi522 жыл бұрын
also sir, adding [] with abcd while printing gives error message
@AmitKhuranaSir2 жыл бұрын
All these are compiler dependent... And i am teaching according to turbo C compiler....