Bifalgorithm post · Computer science one · Comparing Strings and Characters

Why can’t numeric comparison operators be used to compare strings in C?

Why can’t numeric comparison operators be used to compare strings in C? (Computer science one · Comparing Strings and Characters) — "Numeric comparison operato…

Ideas in this flowchart

  • In C, numeric comparison operators cannot be used to compare strings.
  • The expression ("aardvark" < "zebra") is valid C.
  • Although the expression produces a result, that result is not necessarily true or false.
  • The reason is that strings in C are represented as arrays.
  • Arrays are represented as memory locations.
  • These representation issues will be explored in greater depth later.
Feed/

Why can’t numeric comparison operators be used to compare strings in C?

No cover

Channel

Computer science one

1 page

"Numeric comparison operators cannot be used to compare strings in C. For example, we could write (\"aardvark\" < \"zebra\") which would be valid C, and it would even have a result. However, that result wouldn’t necessarily be true or false . The reason for this is that strings in C are actually represented as arrays, which in turn are represented as memory locations . We’ll explore these issues in greater depth later on, but for now 273"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.