c++ - Initialize a variable -


is better declare , initialize variable or declare it? what's best , efficient way?

for example, have code:

#include <stdio.h>  int main() {     int number = 0;      printf("enter number: ");     scanf("%d", &number);      if(number < 0)         number= -number;      printf("the modulo is: %d\n", number);      return 0; } 

if don't initialize number, code works fine, want know, faster, better, more efficient? initialize variable?

scanf can fail, in case nothing written number. if want code correct need initialize (or check return value of scanf).

the speed of incorrect code irrelevant, example code if there difference in speed @ doubt ever able measure it. setting int 0 faster i/o.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -