If we say:
char *p="name";
then how can we do
if(p=="name"){
printf("able"};//this if condition is true but why?
as "name" here is a string literal and p
is a pointer which holds the base address of the string then why the above statement works fine?
It is unspecified behavior whether identical string literals can be considered the same and thus have the same address. So this is not portable behavior. From the draft C99 standard section 6.4.5
String literals:
It is unspecified whether these arrays are distinct provided their elements have the appropriate values. [...]
If you want to compare two string you should use strcmp.