+ 3

Explain this code

Int a=42; a*=a; a/=a; Printf("%d",a); Out put is 1

20th Jan 2020, 7:02 AM
Giri Yaram
Giri Yaram - avatar
4 Respuestas
+ 6
a*=a means a= a*a so a= 42*42= 1764 and similarly a/=a means a= a/a so a= 1764/1764= 1
20th Jan 2020, 7:12 AM
Avinesh
Avinesh - avatar
+ 3
Edit your code a bit to add verbosity of the process. Hopefully this helps clear your doubt. int a = 42; printf("%d *= %d becomes ", a, a); a *= a; printf("%d\n", a); printf("%d /= %d becomes ", a, a); a /= a; printf("%d\n", a);
20th Jan 2020, 7:13 AM
Ipang
+ 2
int a=42; a*= a; /* This means a= a*a, means a=42*42 means a = 1764. Here 1764 will be stored in variable a */ a/= a; /* Here it means a= a/a that means a= 1764 /1764 that was stored in 'a' in previous line , then 'a' become 1 here and 1 will be stored in variable 'a' */ printf("%d ",a); /*Here the value of 'a' that is 1 will be printed that we got in previous line of the code */
21st Jan 2020, 4:09 PM
Vishwa Bharti
Vishwa Bharti - avatar