0

Changing the value of hex (help)

I want to output the hex value of number 1 to 5 using a loop but then the hex is not changing it is still 22ff1c Output target: hex of num=0 is 22ff1c hex of num=1 is 22ff18 hex of num=2 is 22ff14 and so on.. Here is my code: #include <stdio.h> int main() { int num = 1; while(num <= 5) { printf("hex of num=%d is %x\n", num, &num); num++; } }

31st May 2018, 9:32 AM
Anon2023
1 Réponse
+ 2
Just pass the <num> as the second argument to printf, currently you are passing the address of the <num> variable (cmiiw) printf("hex of num=%d is %x\n", num, num); Hth, cmiiw
31st May 2018, 11:14 AM
Ipang