When I write a digit to a variable, the digit is stored until such time as I do not record another value, but I need to make the old value remain, the type is shifted to the high order, and the new value is written to the youngest ....... example : I have the number 1 in the variable, and when I add the number 2 there, do I need to have 12?
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants αλεχολυτ , user194374, Bald , Denis , Kromster 20 Dec '16 at 13:29 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
|
2 answers
these are not bitwise operations. But here's your code
int shift(int num, int digit) { return num*10 + digit; } enjoy so
int x = 1; x = shift(x, 2); cout << x; You can of course rewrite and so
void shift(int &num, int digit) { num num*10 + digit; } and enjoy so
int x = 1; shift(x, 2); cout << x; but it is an amateur.
|
You can do it like this, but I really wonder why?
#include <iostream> using namespace std; class someclass{ private: int a; public: someclass():a(0) {} void operator =(int b){ a=a*10+b; } void show_a(){ cout<<a; } }; int main(){ someclass c; c=5; c=3; c.show_a(); return 0; } |
&,|,&&,||,<<,>>- nick_n_a