need help understanding

have some trouble understanding this bit of this code


#include<iostream>
using namespace std ;
int main()
{
int m, t ;
cin >> m >> t ;
int ans = 0 ;
while ( t < m) {
t*= 2 ;
ans++;
}
cout << ans << endl ;
return 0 ;
}


in the line t*= 2; what does this mean like i dont know what the *= does to the value of t. im new and just started learning and i understand most of this just not what t *=2 is doing, hoping someone could shed some light on this
Hey. Pleasure put all of your code between code tags - http://www.cplusplus.com/articles/jEywvCM9/

t *= 2 ; Doesn't do anything. I believe it's supposed to be t = t*2;

t *=2; is another way of writing t = t * 2; Thanks @AbstractionAnon for clearing that up, got the * mixed up with a pointer


Which multiplies t with 2 each iteration.

So if we put m = 20; and t = 2;

ans would be = 4 because.

2*2 = 4.
4 * 2 = 8;
8 * 2 = 16;
16*2 = 32.

It stops at the fourth iteration.
Last edited on
t*= 2 ; Doesn't do anything.

Huh? t*= 2 ; is a perfectly acceptable way of expressing t = t*2;
No different syntactically than t += 2;
Topic archived. No new replies allowed.