Explain this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 17
int a=42; //a=42 a*=42; //means a=42*42 a/=a; //i.e a=a/a; // so a=(42*42)/(42*42) //so value of a is 1.
20th Jan 2020, 7:16 AM
𝘕𝘉
𝘕𝘉 - avatar
+ 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