-2

In Python we could use if x in list: so I was wondering if there's a similar command in C, so that we don't have to go through the whole thing using a for.

  • You should write a function to loop though the a passed array and return true if found. return false if all elements don't match. Use that function in for. – Robert Jacobs Mar 28 '16 at 19:42

1 Answers1

6

How can you know whether a value is contained in an array without cycling through it? This is exactly what Python does under the hood. No, there's no magical way to instantly know this.

ForceBru
  • 43,482
  • 10
  • 63
  • 98