Library Functions

Q1: If the two strings are found to be unequal then strcmp returns difference between the first non-matching pair of characters.

A True

B False

ANS:A - True

g = strcmp(s1, s2); returns 0 when the strings are equal, a negative integer when s1 is less than s2, or a positive integer if s1 is greater than s2, that strcmp() not only returns -1, 0 and +1, but also other negative or positive values(returns difference between the first non-matching pair of characters between s1 and s2). A possible implementation for strcmp() in "The Standard C Library".


int strcmp (const char * s1, const char * s2)
{                
	for(; *s1 == *s2; ++s1, ++s2) 
	{
		if(*s1 == 0)
			return 0;
	}
	return *(unsigned char *)s1 < *(unsigned char *)s2 ? -1 : 1;
}



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.