For an Int : if (value == 0)
For int
if the value is 0
. it doesn't mean that the parameter is empty, it means that the parameter is holding the value 0
.
Performance-wise, there is no difference. You can check this by inspecting the compiled assembly code.
The assembly code is given below.
#include<stdio.h>
int main()
{
int a=0;
if(a==0)
printf("hello");
}
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $0, -4(%rbp)
cmpl $0, -4(%rbp)
jne .L3
movl $.LC0, %edi
movl $0, %eax
call printf
And for this one,
#include<stdio.h>
int main()
{
int a=0;
if(a)
printf("hello");
}
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $0, -4(%rbp)
cmpl $0, -4(%rbp)
je .L3
movl $.LC0, %edi
movl $0, %eax
call printf
You can see that both the codes are same, thus there is no difference performance-wise.
But, as others mentioned, the FIRST
one is easier to understand and is more clear. That should be used