>> SPEAKER: Recall that in C, all data types have a particular size.
But that size may very well vary based on the computer on which you're using
C. Now, we happen to be using C inside of the CS50 appliance, so inside of
the appliance, how big is a char?
How big is a double?
How big is an int?
How big is a float?
>> Well, let's take a look with some code.
Include standard io.h, int main void.
And now let's begin to declare a few variables whose
sizes we'll then print--
char c, double d, float f, and int i.
Now, I'm not going to store any values in these variables, because I only
care about their particular size.
>> To see their size, I'll use print f, as well as a C operator called size
of, which will answer exactly that question.
Let's take a look.
Print f char, followed by a colon, percent 1, backslash n.
In other words, I want to print out char colon, followed by its size.
>> So I'll include a comma followed by size of c.
Let's now do this again for a double.
Print f, double, percent i, backslash n, close quote, comma, size of d.
Now notice, I'm going to continue using percent i, thereby signifying an
int, because what isn't changing is the units in which I'm measuring the
size of these variables.
>> In fact, size of is going to return some number of bytes, maybe one, maybe
two, maybe more.
But in each case, it will indeed give me an int.
And so that's the place holder I want to use, irrespective of the type,
whose size I'm getting.
Let's do two more print f's.
>> Float, percent i, backslash n, size of f.
Print f, int, percent i, backslash n, size of i.
Let's now save, compile, and run this program.
Make, size of, dot slash, size of, and we see that in the CS50 appliance, a
char is one byte, a double is eight bytes, a float is 4 bytes, and an int
is four bytes, as well.