>

Description

Compares the variable on the left with the value or variable on the right of the operator. Returns true when the operand on the left is greater (bigger) than the operand on the right. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.

Syntax

x > y; // is true if x is bigger than y and it is false if x is equal or smaller than y

Parameter Values

  • x: variable. Allowed data types: int, float, double, byte, short, long.
  • y: variable or constant. Allowed data types: int, float, double, byte, short, long.

Example Code

void setup() { Serial.begin(9600); int x = 3; int y = 2; if (x > y) // tests if x is greater (bigger) than y Serial.println("x is greater than y"); } void loop() { }

The result on Serial Monitor:

COM6
Send
x is greater than y
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTES AND WARNINGS:

Positive numbers are greater than negative numbers.

See Also

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES