-8

Basically which one of the Codes will return 0, faster ?

// if the answer is "the same" because the code is simple than imagine a more complex code variant written in the same way but with more code.

Code 1:

int a = 0;

if(a == 1){ 
    return 1;
}else{
    return 0;
}

Code 2:

int a = 0;

if(a == 1){ 
    return 1;
}
return 0;
RaidenF
  • 3,411
  • 4
  • 26
  • 42

1 Answers1

4

There will be no difference in the compiler generated code. The else is unnecessary but may be written for clarity.

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41