Hello and welcome back.
So I'm now going to learn about primitive primitive types in sea.
So what are primitive types.
Well primitive types are the the data types built into the language itself.
So integer is a primitive type that allows us to store numbers or return numbers.
Char is for characters such as A or B or C for example a single character.
So let's first discuss what void days as you know already based on previous lectures.
Void is a data type.
That means we will return no value.
Basically it's like it is a void.
You know you think of a void in real life.
It's nothing.
So fast.
Passive void basically is it a void basically represents that there is no number or no data of any kind.
That's basically what void means.
But pointers are a little different.
And we'll explain that in another lecture.
Okay.
So next we have char.
So what is a Cha Cha's allow you to store characters.
So I could do something like this for example
and chars eight bits in length or one byte so obviously in C depending on the data type you should use
should depend on how much data you need to store and what it's being used for.
So typically numbers you would use an integer.
In most cases you would even prefer an integer over a char even if the numbers could fit into the char
data type which is a which is one byte a bits.
Now what can a bit store a bits can store change in fifty five number up to two hundred fifty five if
it is unsigned but we will explain the difference between signed and unsigned shortly now.
So you use child when you want to store characters next you have Oh yeah.
Another thing these quotes by here allow us to define a single a single byte as a character.
So this is converted into the decimal equivalent based on the ascii table so as to show short next.
So short is a number just like integer but it can store a lot less.
Short is four numbers that can't store as many bytes as integer if you need to store numbers that are
much larger.
Like above above like thirty thousand forty thousand fifty sixty thousand onwards then your best is
an integer or an unsigned shot.
Explain the signs.
Soon enough however an unsigned shot cannot store more than sixty five thousand five hundred thirty
five as a number so obvious if you want to go higher than that you need to use an integer guys so then
integer as you know is a data type that can store about four billion number up to four billion something
but the the number can only be around four billion if it's unsigned if it's signed the number is about
2 billion.
So if you need to go higher than that you should use a long and long is a huge number.
It is eight bytes in length and it can store a huge huge number.
I can't even tell you what the number is because it's so big.
So you use a long way where you deal with things that are much much larger.
When you deal with numbers that are extremely large.
So quick overview then chars one byte in length shorts are two bytes in length integers are four bytes
in length and longs at eight bytes in length but that assumes you're using a modern process.
If you can policy on embedded or or on older systems then these data type sizes wolves will be different
lengths so make sure you read about that that's why it's hard for me to tell you exactly how much they
stole because it really depends on the architecture if if you're working on a Windows machine or something.
What I've told you is accurate if you're working on an embedded process or something.
All a really old machine than than these these the sizes of these are show are smaller in length.
OK.
So then we have floats.
Now a float is basically a number that the way you can store decimals.
So for example and you it you put an F at the end of literal numbers when you actually enter the number
you put an F at the end to represent float usually as well so floats are great for storing things like
currency for example like pounds and pence.
Dollars and cents.
Now double is a larger floating point number.
So.
So again you can store this.
You can store currencies and stuff like that but double is much bigger than float the same as long is
much bigger than intrinsic.
Okay.
So you would use a double for large numbers.
That that a decimal place and you use a float for smaller numbers than a decimal place but double is
your best use double if you do it in the currency.
So that is the primitive types.
Char Shaw integer long float double.
OK so now let's explain unsigned vs. signed so unsigned is represented by this unsigned keyword.
So all all primitive types can have an unsigned just before the data type is defined as so you can have
unsigned long.
You can have unsigned integer.
And what this basically does is it means it can't go negative.
Unsigned numbers allow a data type to hold more in the positive range but you can't store in the negative
range.
So by default any data type you define is by default signed.
So for example if I get rid of this second.
So for example signed in it m m equals 30 is equivalent to integer.
So sign this basically invisible.
It's always there unless you define unsigned.
Right.
So assigned can go negative and positive.
So you it can be minus 50 or it can be 50.
It can also be zero.
Now unsigned can only be 50 and zero.
You can't go negative if you try to go negative on an unsigned integer or unsigned anything in a loop
back around.
So essentially it will become the highest number possible for that data type and that's what happens
when you exceed the maximum boundaries and see they look back around.
So that's very important to know that.
So the the difference here then is if you want a positive number but you don't care about negative you
can use unsigned but if you need negative as well then signed is best but unless you're working with
much larger numbers you won't have to worry about signage too much.
If you are defining some sort of file format then obviously you'd need to take more care whether you
signed or unsigned things but essentially use unsigned if you need to.
And if you won't have negative numbers because that's very important to note that and the data type
you choose will depend exactly on how much data you're going to be storing and on circumstance if you're
storing in a file for example.
And you know that like for example doing using an integer here even though you only work with low numbers
it's not so bad.
But if you're working if you're going to be working with files where store where the man you store is
pretty crucial then you should be more careful.
So for example if I if I know that my number won't be above two hundred fifty five and will always be
above minus one.
In other words it won't be negative then it makes sense to use an unsigned char because if I use a char
what happens is it becomes signed which means that I can have negative I think is negative one hundred
and twenty and then an M Plus One hundred and twenty seven.
Right.
But if I use unsigned then I can only have up to two hundred and fifty for a positive.
But by cent is unsigned I extend the amount of data I can store in that but I can't have negative numbers.
So using that I can have in the negative range and the positive range but I basically lose half of the
positives.
The potential length because I need to take into account that I can have negative numbers.
You can sign it then you use the full amount of bytes.
Basically extending the number you can store in that amount of bytes that char provides which is one
bite you sign it.
You have the negative range but you lose some of the positive range.
So there are important things to note very important things to note.
Now that is data types and I hope that makes sense because if it doesn't send me a message and I'll
make follow up video but essentially unsigned and signed up and concepts you should know.