pointer and string part1

  Рет қаралды 5,106

GATE CSE LECTURES BY AMIT KHURANA

GATE CSE LECTURES BY AMIT KHURANA

Күн бұрын

Пікірлер: 13
@shahshah-wi9kk
@shahshah-wi9kk 6 ай бұрын
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; }
@aryushgupta8680
@aryushgupta8680 5 ай бұрын
Thanks buddy!!
@GateCse-2025
@GateCse-2025 3 ай бұрын
thanks chatgpt.
@satyaprakashsingh952
@satyaprakashsingh952 3 жыл бұрын
I have learing your all pointer video sir Too good explained by you
@sammanluitel3018
@sammanluitel3018 3 жыл бұрын
Please make complete c tutorial please with many examples of coding problems using D's algo aswell
@AmitKhuranaSir
@AmitKhuranaSir 3 жыл бұрын
I will make playlist on C language soon.....
@atultripathi52
@atultripathi52 2 жыл бұрын
sir you are wrong at 2.25 "abc"=="abc" returns 1
@guru_cse
@guru_cse Жыл бұрын
It is compiler dependent.
@dherendrasingh4761
@dherendrasingh4761 Жыл бұрын
right , me also check on online gdb, getting true condition result
@dherendrasingh4761
@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
@rndmdpe23
@rndmdpe23 7 ай бұрын
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
@atultripathi52
@atultripathi52 2 жыл бұрын
also sir, adding [] with abcd while printing gives error message
@AmitKhuranaSir
@AmitKhuranaSir 2 жыл бұрын
All these are compiler dependent... And i am teaching according to turbo C compiler....
pointer and string part 2
5:08
GATE CSE LECTURES BY AMIT KHURANA
Рет қаралды 4,3 М.
Harsh reality of the coaching Industry....
7:31
GATE CSE LECTURES BY AMIT KHURANA
Рет қаралды 2 М.
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
Почему Катар богатый? #shorts
0:45
Послезавтра
Рет қаралды 2 МЛН
Every team from the Bracket Buster! Who ya got? 😏
0:53
FailArmy Shorts
Рет қаралды 13 МЛН
A DAY IN LIFE OF A SOFTWARE ENGINEER
12:41
Bhumi Sorathia
Рет қаралды 259
hii
SSC_MATHSbySS
Рет қаралды 64
Mentorship sesion #motivation #trending #iit #vjsir
Nucleus - VJ Sir
Рет қаралды 69
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН