Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How do I compare character data stored at two different memory locations?

Answer: Sometimes in a program we require to compare memory ranges containing strings. In such a situation we can use functions like memcmp( ) or memicmp( ). The basic difference between two functions is that memcmp( ) does a case-sensitive comparison whereas memicmp( ) ignores case of characters. Following program illustrates the use of both the functions.

#include <mem.h>

main( )
{
char *arr1 = "Kicit" ;
char *arr2 = "kicitNagpur" ;

int c ;

c = memcmp ( arr1, arr2, sizeof ( arr1 ) ) ;

if ( c == 0 )
printf ( "nStrings arr1 and arr2 compared using memcmp are identical" ) ;

else
printf ( "nStrings arr1 and arr2 compared using memcmp are not identical"
) ;

c = memicmp ( arr1, arr2, sizeof ( arr1 ) ) ;

if ( c == 0 )
printf ( "nStrings arr1 and arr2 compared using memicmp are identical" )
;
else
printf ( "nStrings arr1 and arr2 compared using memicmp are not
identical" ) ;
}

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook