1 votes 1 votes What will be the output ? #include<stdio.h> int main() { char *str1 = "xyz"; char *str2 = "xyz"; if(str1 == str2) printf("equal"); else printf("unequal"); return 0; } Programming in C strings pointers programming-in-c + – Abhisek Saha asked Nov 15, 2017 Abhisek Saha 711 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Ashwani Kumar 2 commented Nov 15, 2017 reply Follow Share It will be equal, as string "xyz" is stored at some memory location say 1000 as base address. Then two pointer to characters str1 and str2 points to the same string and contains the address 1000. Hence equal 0 votes 0 votes saipriyab commented Nov 20, 2017 reply Follow Share str1 and str2 are string constants which are stored in read only memory so once it is allocated memory again if we try to initialize the same value to another variable new memory will not be created instead it again assigns to the previously allocated memory??? 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes string xyz is store two diffrnt memory location and address of str1 and str2 is diffrent so if statement become false it must return unequal abhishekmehta4u answered Nov 18, 2017 abhishekmehta4u comment Share Follow See all 0 reply Please log in or register to add a comment.