Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Do you think operator < is faster than <= in C/C++?
No, the operator < takes same time to execute as operator <= takes. Both operators execute similarly and take same execution time to perform the execution of instructions.
There is a jcc( jump instruction) at the time of compilation and depending upon the type of comparison, it jumps to the instructions. The following are some of the comparison type −
je − Jump if equal
jg − Jump if greater
jne − Jump if not equal
jge − Jump if greater or equal
There is only one difference between operator < and operator <= that the operator < executes ‘jg’ instruction while the operator <= executes ‘jge’ instruction. But both operators take same time to execute.
Here is an example of operator < and <= in C language,
Example
#include<stdio.h>
int main() {
int a = 8;
int b = 8;
if(a<b)
printf("b is greater than a\n");
if(a<=b)
printf("b is greater or equal to a");
else
printf("b is smaller than a");
return 0;
}
Output
Here is the output
b is greater or equal to a
