Revision as of 20:49, 13 May 2024 by Admin (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Exercise


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;

  1. 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;

00