dimanche 8 mars 2015

c++: what does this insertion expression do and how does it work when passing as a function argument?


What's the meaning of binary(number >> 1), and how does it work in the following code? Could somebody explain it to me in detail? Thank you!



#include <iostream.h>

void binary(int);

void main(void) {
int number = 3;
cout << number << endl;
binary(number);
}

void binary(int number) {
if(number <= 1) {
cout << number;
return;
}
int remainder = number%2;
binary(number >> 1); //How does this work exactly?
cout << remainder;
}



Aucun commentaire:

Enregistrer un commentaire