{"id":2136,"date":"2016-10-01T00:01:35","date_gmt":"2016-10-01T07:01:35","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2136"},"modified":"2016-10-08T08:22:32","modified_gmt":"2016-10-08T15:22:32","slug":"the-curse-of-typecasting","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2136","title":{"rendered":"The Curse of Typecasting"},"content":{"rendered":"<p>In the C language, it&#8217;s called typecasting: A variable of one type &mdash; for an instant &mdash; masquerades as another variable type. In Hollywood, however, it&#8217;s a curse: The typecast actor can play roles other than the one he&#8217;s famous for creating. That sucks.<br \/>\n<!--more--><br \/>\nC language typecasting doesn&#8217;t suck. Often it&#8217;s necessary to recast a variable as another type to perform an accurate calculation.<\/p>\n<p>For example, you need to divide two integers. To obtain the correct calculation, you cast each as a <em>float<\/em>. The result can be used immediately or saved in a <em>float<\/em> variable, but it&#8217;s a floating-point result and not an <em>int<\/em> value that&#8217;s calculated.<\/p>\n<p>For this month&#8217;s Exercise, your task is to take an <em>int<\/em> variable <code>apple<\/code>. Assign it the value 65. Then use three <em>printf()<\/em> statements to display the value of <code>apple<\/code> as an <em>int<\/em>, <em>char<\/em>, and <em>float<\/em>.<\/p>\n<p>If you&#8217;re an old hand at C, this Exercise should be easy. If you&#8217;re new, then this Exercise is a welcome respite from my recent spate of angry, involved Exercises.<\/p>\n<p>Please attempt this Exercise on your own before you take a peek at <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=2150\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not every Exercise needs to be a bastard. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2136\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2136","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2136"}],"version-history":[{"count":3,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2136\/revisions"}],"predecessor-version":[{"id":2172,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2136\/revisions\/2172"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}