The output of the StrCmp() function in the Ring programming language

Hello

see strcmp(“hello”,”hello”) + nl +
strcmp(“abc”,”bcd”) + nl +
strcmp(“bcd”,”abc”) + nl

if the two strings are the same then it returns 0

abc and bcd aren’t the same. in the second line it returns -1 and in the third line it returns 1

in the second line we compare between “abc” and “bcd”
not equal because the first letter in “abc” = “a”
and the first letter in “bcd” = “b”
so we have “a” != “b” and “a” < “b”
so we get output = -1

In the third line we have “bcd” and “abc”
the first letter in “bcd” is “b” and the first letter in “abc” is “a”
so we have “b” != “a” and “b” > “a”
so we get output = 1

Note :

ASCII(“a”) = 97
and ASCII(“b”) = 98
So “a” < “b” because 97 < 98

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s