Sunday, August 2, 2009

What is the c++ code for using characters instead of nos in the 'if' statement?I need to know this ASAP.

basically when we use the 'if' statement in c++ we only use nos.but using strcmp in c++ we can use characters.i need to know the code and way it is entered as well as the functions in it.

What is the c++ code for using characters instead of nos in the 'if' statement?I need to know this ASAP.
Your Question is not very clearly,


we can use if statement with characters...


eg. if (a[1]=='a')


do something


else somw other thing.





what exactly u r asking for...
Reply:strcmp(a,b). This gives an integer. if you have String blah = "a" and String blah2 = "b" (don't have to be characters), and compare


strcmp(blah,blah2) you'll get a number less than 0, because a is lexocigrayhically less than b. Likewise, strcmp(blah2,blah) would yield a value greater than 0, and if both blah and blah2 = "a", it would yield eactly 0.


No comments:

Post a Comment