0

Can someone explain this kind of statement(s)? I didn't get it.

  data[i] = ((data[i] == div[i]) ? '0' : '1');
yareenm
  • 1
  • 1

1 Answers1

3

It's an if-else statement but the conditional operator takes less space and helps to write the if-else statements in the shortest way possible.

So , your expression can be visualized into if-else statement as:

#include <stdio.h>
int main(){
// Code ...
if(data[i]==div[i])
    data[i]='0';
else
    data[i]='1';
}

** ‘?:’ takes three operands to work, hence they are also called ternary operators.

TheKing
  • 136
  • 9