Problem Solving

Photo by Kevin Ku on Unsplash

Problem Solving

·

2 min read

How do integer variables act like float/double variables?

Ans: when we declare an integer number, we write (int num = 5;) and when we declare a double number, we write (double num2 = 5.49;)

if we want to divide or multiply between int and double numbers, we can't get the correct answer. we can get the correct answer by calculating between double and double numbers. we can store int number to a double number. but when we declare a double number, it takes 8 bits of the memory. the integer variable takes 4 bits of the memory. so I don't want to put an integer variable to a double variable. it takes extra 4 bits of memory. so what can we do? is it possible to calculate an int variable with a double variable?

Yes, It's possible. It is very simple. just put the value with a decimal number. e.g (int num = 5.0;). Now it acts like a double number. we can multiply or divide this number by any other double number. and we will get the correct answer. Thank you :)

int, long int, and long long int

the size of int is 4 bytes (32 bits), long int is 4 bytes (32bits) and long long int is 8 bytes (64bits). when we store large numbers, we have to store them in the long long int variables. printf("%lld") for the long long int.