Hello. I want to provide another challenge for you for this operator
section.
Mainly I want to demonstrate the use of the sizeof operator.
So let's start in describing the requirements.
In this challenge, I want you to create a c program that displays the byte sizes
of basic data types supported in c.
So the reason this challenge is kindda cool is because
I keep mentioning but maybe it hasn't stuck in your head that
depending on the actual system you're running on,
whether different operating system or
different architecture hardware-wise,
you may have different memory sizes for the various data types.
Int may be 4, int may be 8.
Doubles maybe 8 or 16 or whatever the case may be.
And it's very important to understand that.
And if you start hard coding numbers,
it's going to cause problems your program. So you want to use the sizeof operator.
Now you don't necessarily have to worry if your program is running on a certain system,
it's always going to work the same.
So this challenge demonstrates that it forces you to use sizeof.
Now we're going to be using sizeof operator a lot more when we talk about pointers,
but this will get you a little challenge that'll get your hands a little dirty with this operator
and also get you more familiar with some format specifiers related to this operator.
So again, depending on the system you're running, the output might be different for this program.
But you're to write a program that displays some basic data type sizes.
It's pretty simple, shouldn't take you that long.
But what I want you to do is use the printf function to display the byte size of the following types.
Int, char, long, long long, double, long double.
And the usefulness of this program will be to run it on multiple
actual computers to see the differences. But when you print out this data,
you can use the percent zd format this is supported in C99, so you should be good.
But this format specifier will help format each size and print it out correctly.
Other than that, this function or this program
is really just going to use the sizeof operator
and demonstrate how sizes vary from memory for different data types.
Again, the key will be to test this on more than one computer to see the differences,
but this program should not take you that long.
You don't even actually have to create variables if you're clever. You can just use the printf statements
themselves and see this is more for your knowledge on the sizeof operator.
In addition to these challenges, definitely do more challenges on using the operators
for converting different types. There can be all sorts of conversion.
I mentioned the Fahrenheit to Celsius, but you could come up with conversions for
converting any type of data set
or just go into your math book and and look for different equations
and try writing programs for,that will also help you get familiar with
some of the different operators in c
and how they're supporting, how they're used.
But good luck on this one. Again, it shouldn't take you long.
I'll provide a quick solution in the next lecture, show you how to do this, but
pretty straightforward, just using the sizeof operator. Thank you.