Integer types, and integer overflows, in C
C offers you the ability to define a whole variety of integer types:
short int my_number;
long int my_number;
typically occupying 16, 32 and 64 bits of memory (but that is NOT a standard, and you may find different on some systems). And the amount of memory that's declared controls the minimum and maximum numbers that can be held. C, as a language which assumes the programmer knows what (s)he is doing, will not check for overflow for you, and will give results which are plain wrong arithmetically if you exceed the limits.
There's an example [here]
from yesterday's C course, where I attempted to fill an array with an exponentially growing series of numbers, and ended up bursting even the capability of a long int
. You'll note that (on my machine, in this case), I ended up getting zeros back rather than the largest number the machine can handle - a dramatic failure of my code.
There's a header file - limit.h
- which #defines a whole load of constants such as INT_MAX to help you program to check for limits. There's an example of it in use [here]
in a training example from our C Programming course
(written 2012-01-25, updated 2012-01-28)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesC201 - C and C based languages - C Language Fundamentals 
C - why is slow to write and debug) but fast to run? - (2015-11-01) 
Preprocessor directives in C and C++ - what they mean - (2015-10-27) 
Learning to program - variables and constants - (2014-11-22) 
BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09) 
Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05) 
Your program - you just provide the filling in the sandwich - (2011-04-08) 
Learning to write good programs in C and C++ - separating out repeated code - (2011-01-04) 
Staring a C course with Hello World - why? - (2010-06-30) 
What does const mean? C and C++ - (2010-01-15) 
Variables and pointers and references - C and C++ - (2009-01-23) 
Compiling C programs with gcc - an overview - (2008-06-10) 
Turning C from source to a running program - (2006-10-06)
Some other Articles
Looking upBack to UniChars, char arrays and strings in C. Some early cautions and pitfalls.Are we one man, one vote? No, and we never have been. Integer types, and integer overflows, in CDefining, declaring and initialising variables in CPromoting a single one of your domains on the search enginesLearning about how to help people learning - and retaining C++ Courses - do I get official certification at the end of my Well House course?Emergency First Aid Provision at Well House Manor - part of the service
4692 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94 at 50 posts per page
This is a page archived from The Horse's Mouth at
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).