excans:780ad9be61: Difference between revisions
From Stochiki
(Created page with "* The standard way of assigning 3.14 to pi is: <syntaxhighlight lang="C"> double pi; pi = 3.14; </syntaxhighlight> ** 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: <syntaxhighlight lang="C"> const float pi = 3.14; #define pi 3.14 </syntaxhighlight> * Yes, for example : <syntaxhighlight lang="C"> int a = 67; double b; b = a; </syntaxhighlight> * Yes, but a cast...") |
mNo edit summary |
||
Line 21: | Line 21: | ||
b = (int) a; | b = (int) a; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''References''' | |||
{{cite web |url = https://en.wikibooks.org/w/index.php?title=C_Programming/Exercise_solutions&oldid=3676254 |title= C Programming/Exercise solutions | author = Wikibooks contributors |website= Wikibooks |publisher= Wikibooks |access-date = 13 May 2024 }} |
Latest revision as of 21:51, 13 May 2024
- 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.