-1

Possible Duplicate:
Speed difference between If-Else and Ternary operator in C…?

This is a very simple question, does the ternary operator increase the speed of execution in comparison to if else statement?

Community
  • 1
  • 1
Dom045
  • 103
  • 1
  • 7
  • @FosterZ: If you don't have an answer to my question, don't make a comment here, keep your opinion to yourself, no one asked you for it. – Dom045 Mar 06 '12 at 13:24
  • i do have answers, but i wanted you to do a search first, don't just rush in here to ask questions. – FosterZ Mar 06 '12 at 14:09

1 Answers1

0

No. Most languages parse it to a very similar syntax tree. Any jit/optimizer is going to collapse it into 'basic blocks' of simple instructions without jumps; and from that point on it will optimize the same.

There could, of course, be some really bad systems out there for which this is not true; but gcc/msvc/c# will all deal with it equally well.

It's abundance can usually be associated with the fact that it is an expression instead of just a logic statement. This makes it all to easy to do things like (note: really ugly example ahead):

size_t n = strlen( pszVar == NULL ? "" : pszVar );

Joe
  • 2,946
  • 18
  • 17