Archive for March, 2011


This explanation was written keeping in mind the confusion caused by the fact that one has two different types of floating point numbers at their disposal. Read below to find out what you could be missing out on in your C programs.

Firstly, you must know that a "Floating point number" refers to a number with a decimal place followed by a number or numbers. Also there are what some may refer to as "Two types of floating point number types." Although they are more or less the same with different features, as they do the same thing in slightly different ways.

 

What differences will I notice when I opt for “double” as opposed to “float” or vice versa:

  • By using the "float" function to create a floating point number you are creating a variable that is capable of storing a numerical data value (number) within itself with up to 7 numbers after the decimal point. Wow! Accuracy to seven points, that sounds crazy. This is the most commonly used floating point variable type.
  • By using the "double" function to create a floating point number, you are creating a variable that is capable of storing a numerical data value inside itself with not seven, but 15 numbers after the decimal point. Which means you can have up to 15 point of accuracy on a single integer. This type of floating point number variable is used more rarely, in applications that require utmost accuracy.

Perhaps you would like to know about signed and unsigned integers in C while you are here? If so you must see the explanation linked below:

https://chafflube.wordpress.com/2011/03/20/signed-vs-unsigned-integer-variables-in-c/

Hopefully this explanation has removed your once-hazy understanding of the different types of "Floating point numbers" in C. Enjoy your newfound C language knowledge.

This post was written to elaborate on any curiosities you may have on the differences between signed and unsigned integer variables in C. Read below to find out exactly what they are and why you should be using the both of them.

First and foremost, a signed integer can contain numbers in a range built on the same amount of numbers as that of an unsigned integer’s range, although they are at a different end spectrum.
By creating a variable using the "int" function, you have created a signed integer variable. This default can be reversed by using the "unsigned int" function. Why would you want to do that you ask? Well that is simple:

  • A signed integer variable can contain a numerical data value within the range of -32768 to 32767.
  • An unsigned variable can contain a numerical data value within the range of 0 to 65535.

Now why would that be useful? You may be wondering. It is quite simple. For a vast majority of applications you will use the default signed integer variable type. Which is no less than satisfactory; unless you wish to create a variable that will be used to contain a number larger than 32767 or a variable that will force a positive number.

 

A signed integer variable can be very volatile if used in incorrect situations. Unlike a floating point variable, the signed integer variable will become a negative number if its range is exceeded, if the range is exceeded enough, it may even become positive again. This creates a potential for much inaccuracy. For example, if you were to use the "scanf()" function to allow the user at the keyboard to enter a value for a signed integer and he or she decided to enter the value 32768 for example, which is one number above the allowed maximum for a signed integer variable, then the value of the signed integer variable will become something crazy. In my case it returned "909586995".

 

When using an unsigned integer, you have a higher range in positive numbers, although you have no option for negative numbers. The range for an unsigned integer is, as stated before, 0 to 65535. Which is much more practical for a majority of more technical applications that require avoidance of negative numbers.

 

Now that you have indulged your mind in the wonderful language that is C. Perhaps you would like to head over to the explanation on the different types of “Floating point numbers” linked below:

https://chafflube.wordpress.com/2011/03/20/signed-vs-unsigned-integer-variables-in-c/

I do so hope that this enhanced your knowledge on the use of signed and unsigned integer variables in the C language. Enjoy your newfound C integer variable knowledge.

%d bloggers like this: