Username:
Password:
Advanced C Programming Tutorials

Types of Data / Integers

Subtitles of the Movie

C is close to the hardware and the size of integer data types is determined by the sizes of integer data types natural to the underlying hardware. When C first appeared and began to spread, there was a lot of variety to the hardware so the size of a care, for example, could be six, seven, eight, nine or even twelve bits. We don't have that kind of variety in computers today so the sizes have stabilized. But you need to know if you use C on a unique computer, you will need to check the sizes of the integers to make sure they can hold the types of values you want to be able to use. You can always count on an int for being fast. It will always be faster than or as fast as any other integer type on the machine. Also, when C first appeared, there were only eight integer data types. Since then things have expanded a bit. There are so many that you almost need a cheat sheet. There are now 15 different ways of declaring an integer. The character data types are called what they're called because while they are integers, they come in most handy for holding ASCII character values. Some people pronounce the c-h-a-r as care, others as char. I use care because the name is short for characters. The normal link for a care is eight bits. Declaring it as a care or as a signed care will have the same result. The unsigned care is really the only variation. The short integer is normally 16 bits. The declaration of a signed short is the same as a declaration of a short. The unsigned short is the only real variation here. An int is normally 32 bits. It's the natural length of an integer data type for the hardware. This is the one where the variation size occurs most often. On a lot of embedded systems, an int is 16 bits. A signed int as the same as the declaration of an int. The unsigned int being the only variation. A long was once almost always longer than an int but now it's almost always the same as an int. It's normally 32 bits. Even on systems where the int is 16 bits, a long is 32 bits. A long and a signed long are the same thing. Again, these are some of the new ones. It was added by the C standard C99. The long long is normally 64 bits. A long long and a signed long are the same things with unsigned long long being the only variation. Another new data type added by C99 is the Bool type. As you know, in C in a conditional expression, zero is false and any other value is true. A Bool data type is an integer that can only hold the values of zero and one so it can only be used for true and false. It was given this odd name to try not to have any conflict with any existing code because some people had used the pre-processor to define their own Boolean type. If you're going to write new code using the Boolean data type, you probably want to include the standard header. That way you're able to use the lowercase Bool name for your declarations of your Boolean variables and the names true and false, they're defined with the two values that can be stored in a Boolean variable. One note about these names; declaring a variable as a short or a long is the same as declaring it as a short int or a long int. In the original C language, the words short and long were adjectives used to describe the type of int. They still are but you don't have to enter the word int any more, just unless you want to. Those are your basic 15 types of integers. Throw in the modifiers of const, static, volatile, register and extern and the possible combinations for an integer declaration are in the hundreds. I'll be going over these modifiers and how they can be used as this course progresses.

Tutorial Information

Course: Advanced C Programming
Author: Arthur Griffith
SKU: 33965
ISBN: 1-935320-24-6
Release Date: 2009-01-30
Duration: 5.5 hrs / 82 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available