Exercise
ABy Admin
May 13'24
Answer
- The standard way of assigning 3.14 to pi is:
double pi;
pi = 3.14;
- Since pi is a constant, good programming convention dictates to make it unchangeable during runtime. Extra credit if you use one of the following two lines:
const float pi = 3.14;
#define pi 3.14
- Yes, for example :
int a = 67;
double b;
b = a;
- Yes, but a cast is necessary and the double is truncated:
double a=89;
int b;
b = (int) a;
References
Wikibooks contributors. "C Programming/Exercise solutions". Wikibooks. Wikibooks. Retrieved 13 May 2024.