{"id":7743,"date":"2026-09-01T00:01:37","date_gmt":"2026-09-01T07:01:37","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7743"},"modified":"2026-09-01T07:55:24","modified_gmt":"2026-09-01T14:55:24","slug":"too-big","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7743","title":{"rendered":"Too Big"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>The C language comes with a variety of data types that hold integer (whole number) values. But each type is limited by its size. The issue is to ensure that whatever value the program is manipulating never exceeds the given size.<br \/>\n<!--more--><br \/>\nHere is a summary of C language integer data types:<\/p>\n<table>\n<thead>\n<tr>\n<th>Type<\/th>\n<th>Width<\/th>\n<th>Minimum Range<\/th>\n<th>Maximum Range<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>signed char<\/td>\n<td>1 byte<\/td>\n<td>-128<\/td>\n<td>127<\/td>\n<\/tr>\n<tr>\n<td>unsigned char<\/td>\n<td>1 byte<\/td>\n<td>0<\/td>\n<td>255<\/td>\n<\/tr>\n<tr>\n<td>short int<\/td>\n<td>2 bytes<\/td>\n<td>-32,768<\/td>\n<td>32,767<\/td>\n<\/tr>\n<tr>\n<td>unsigned short int<\/td>\n<td>2 bytes<\/td>\n<td>0<\/td>\n<td>65,535<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>4 bytes<\/td>\n<td>-2,147,483,648<\/td>\n<td>2,147,483,647<\/td>\n<\/tr>\n<tr>\n<td>unsigned int<\/td>\n<td>4 bytes<\/td>\n<td>0<\/td>\n<td>4,294,967,295<\/td>\n<\/tr>\n<tr>\n<td>long int<\/td>\n<td>4 or 8 bytes<\/td>\n<td>(See above\/below)<\/td>\n<td>(See above\/below)<\/td>\n<\/tr>\n<tr>\n<td>unsigned long int<\/td>\n<td>4 or 8 bytes<\/td>\n<td>0<\/td>\n<td>(See above\/below)<\/td>\n<\/tr>\n<tr>\n<td>long long int<\/td>\n<td>8 bytes<\/td>\n<td>-9,223,372,036,854,775,808<\/td>\n<td>9,223,372,036,854,775,807<\/td>\n<\/tr>\n<tr>\n<td>unsigned long long int<\/td>\n<td>8 bytes<\/td>\n<td>0<\/td>\n<td>18,446,744,073,709,551,615<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Various C functions, typedefs, and defined constants are used to help your code with these ranges and values, but in all cases there is a minimum and maximum number that sits safely in an integer space.<\/p>\n<p>When I first learned to program, I was curious why programmers didn&#8217;t always use the maximum size, such as a <em>long long<\/em>. (Though, back then the largest integer value was a 16-bit <em>int<\/em>.) The answer is efficiency, but also storage conservation. Especially in the olden days, uses the smallest container that accommodated a given value was the best way to use memory.<\/p>\n<p>The issue that triggers when to use the next largest integer container is overflow.<\/p>\n<p>For example, the next <em>char<\/em> value after 127 is -128, which makes no sense to anyone unfamiliar with programming: Adding one to a <em>char<\/em> variable that holds 127 suddenly subtracts 255 from the value. Weird to mortals, but sensical to a programmer.<\/p>\n<p>Ditto for <em>unsigned<\/em> data, where you add one to <em>short int<\/em> 65,535 and you&#8217;re back at zero again.<\/p>\n<p>Finding the integer overflow values is the topic for this month&#8217;s C programming exercise.<\/p>\n<p>Write a program that counts from zero on up. Flag when the value overflows for the <em>char<\/em> data type. Don&#8217;t cheat by using <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=1190\">defined constants<\/a> from the <code>limits.h<\/code> header file or anything else that&#8217;s already coded. Your program must report when the value flips for a signed and unsigned <em>char<\/em> value.<\/p>\n<p>Here is a sample run from my solution:<\/p>\n<pre>'signed char' overflow at 127\r\n'unsigned char' overflow at 255<\/pre>\n<p>Please try this exercise on your own before checking out my solution, which I&#8217;ll post in a week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An integer can be only so large. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7743\">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-7743","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\/7743","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=7743"}],"version-history":[{"count":6,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7743\/revisions"}],"predecessor-version":[{"id":7760,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7743\/revisions\/7760"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}