When programmers like you exists, it is easy to learn any tough programming language. Thanks for the good work. Though I am learning D, there exists some elements of C. So this video helped me a lot.
Great video, as are all the rest. Your presentation style is very clear and has really helped me get my head around some of the intricacies of C. Thank you!
Ahh, you're right. I think I wanted to say "maximum value of size_t + 1". Was referring to the idea in this video: code-vault.net/lesson/tbf9m6ld3d:1603733523875
It is dangerous, because the range of strlen is like 0..2^32-1 usually and int range is like -2^31..2^31-1, so if strlen is more then 2^31-1, comparing will fail. You could use unsigned int, that is better, but the problem is, this all assumes certain things about the size of a size_t. On some systems, maybe the size of size_t might not match unsigned. So best just to use size_t.
And the range of size_t is not always what I stated, it is just typically that range. So that is what I meant by it could be different on different systems.
Sorry about that issue, my mixer settings were wrong. It's fixed in later videos, but unfortunately I can't fix this on the videos that already exist. Hopefully UA-cam will let us replace audio at a later date within their editor
It's more like for clarity. Whenever you see a "size_t" in your code you know it refers to some kind of size (maybe of an array or block of memory) but when you see an "int" you HAVE to read the code to understand what's it used for (if the name of that variable isn't 100% clear) Also, you will get a warning if you try to assign to a "size_t" variable a negative number, which is always good for catching code errors before running the code.
While you can't use an int to store the result of that operation, but you can do that with an (unsigned or signed) long long, like so: unisgned long long x = 40000; x *= 100000; printf("%llu ", x); Note that doing the operation in one line directly won't work: unsigned long long x = 40000 * 100000; You have to either do it in steps (like above) or cast one of the literals: unsigned long long x = (unsigned long long) 40000 * 100000; I may make a video on this topic as it's kinda confusing at first glance
I guess you're referring to the overflow that can be present when using size_t (or other unsigned integer types). Basically: for (unsigned char i = 0; i < 256; i++) { // This loop will forever execute } That's just because, in this case, an unsigned char can only store numbers between 0 and 255 (inclusive), so, when i is 255 and we increment it by 1, it goes back to 0 due to what we call an overflow
It's actually very simple. They are the same as size_t just they are of 8 bits and 16 bits respectively. ssize_t is signed (meaning it can retain negative numbers). I might make a video on this in the future
@CodeVault What u're a saying in the video is not wrong, at all, but it's missing the point, the reason for size_t to exist. I'll try to explain. Size_t as it's name says it's the type wich represent the size (in bytes ofc), as you have shown in the video it's used in function like strlen and also sizeof as the return type; but the real reason to have a type defined for size is compatibility. The point of size_t is to be able to represent the maximum size of an object, witch ipotetically could occupy the whole ram, and since there're different types of architectures it has to account for that. What i mean with that? Let's say you're working on a 32 bit arch, that's a 32bit AddressBus, witch can address at max 2^32 bytes (not counting for sectors, for simplicity) you have to be able to represent the maximum size of an object occupying 2^32 bytes of memory, in a 64bit arch you have to be able to represent the size of a 2^64 bytes object (witch is huge); if you were to write your code using a long int instead of size_t on a 32b arch and then use your app on a 64b arch you would get in trouble, since an object could be many times larger that you expected. When you went and checked the definition for size_t, what could be noticed is that it has different definitions for architecture. Think it through, it's kinda logic, it has to be like that. In short, size_t needs to be able to represent the maximum size of anything based on the architecture it's been used in. Hope i made it clear, i'm not as good at explaining things and english is not my language. edit: and also i forgot to mention, that's why you should use it as an iterator in combination with function witch returns size_t,; an int could be not enough and it might cause problems.
@@thecriminal87 I understand what you mean. Thanks for the explanation. In retrospect this video is lacking this explanation of a fundamental aspect of size_t. I think I'll make another video explaining this properly
Sorry but you speek heavily unclearly. 0:24 - you say what i want to do is "etari toverit"... for what.... just want to "etari toverit". What does "etari toverit" mean?
When programmers like you exists, it is easy to learn any tough programming language. Thanks for the good work. Though I am learning D, there exists some elements of C. So this video helped me a lot.
Thanks for the thorough explanation!
If you wear an earphone, when he types, you can feel some vibration !
I know... I still need to figure out some sound settings for the microphone. It's a bit of an odd issue
@@CodeVault yes man plz fix it. I was watching your video at night, and those vibration gave me horror vibes😂😂
@@abhi1110 Do you know if the same thing happens with the more recent videos? I have tweaked it quite a bit since this video.
I thought it was an earthquake
strlen should be called before the loop, otherwise you got O(N^2) instead of O(N).
Just continue what you are doing...
be unique and simple....
Great video. Keep them coming. Your English is fine. Ignore the haters.
Great video, as are all the rest.
Your presentation style is very clear and has really helped me get my head around some of the intricacies of C.
Thank you!
4:20 It would loop forever only if a
Ahh, you're right. I think I wanted to say "maximum value of size_t + 1". Was referring to the idea in this video: code-vault.net/lesson/tbf9m6ld3d:1603733523875
Thanks im studying C and my textbook just vaguely mentioned this so i needed some further explanation!
It is dangerous, because the range of strlen is like 0..2^32-1 usually and int range is like -2^31..2^31-1, so if strlen is more then 2^31-1, comparing will fail.
You could use unsigned int, that is better, but the problem is, this all assumes certain things about the size of a size_t. On some systems, maybe the size of size_t might not match unsigned. So best just to use size_t.
Nicely explained!
I meant to say, might not match unsigned int, but unsigned with no type is an alias for unsigned int anyway.
And the range of size_t is not always what I stated, it is just typically that range. So that is what I meant by it could be different on different systems.
it wont go forever, even if strlen is max size_t, because you are comparing
Ty so much for making this
Ok,
now tell me who can feel that heavy bass boom sound at 1:20
Edit: I like it
(I was watching this this video at midnight with my headphones on)
Sorry about that issue, my mixer settings were wrong. It's fixed in later videos, but unfortunately I can't fix this on the videos that already exist. Hopefully UA-cam will let us replace audio at a later date within their editor
@@CodeVault I am sorry but i was not pointing out mistake. I was enjoying that sound XD. Video is perfect
so basically its only imporant for efficiency but int works fine, thanks
It's more like for clarity. Whenever you see a "size_t" in your code you know it refers to some kind of size (maybe of an array or block of memory) but when you see an "int" you HAVE to read the code to understand what's it used for (if the name of that variable isn't 100% clear)
Also, you will get a warning if you try to assign to a "size_t" variable a negative number, which is always good for catching code errors before running the code.
@@CodeVault thanks for the comment, knowing this it would make reading code so much easier. Also the non negative is a huge plus. Subscribed :)
your typing speed is amazing in coding...
Another very good course from a master!
Hello! Thank you very much for your videos! Could you explain how to multiply 40,000 x 100,000 in C. Only with integer type? Thank you!
While you can't use an int to store the result of that operation, but you can do that with an (unsigned or signed) long long, like so:
unisgned long long x = 40000;
x *= 100000;
printf("%llu
", x);
Note that doing the operation in one line directly won't work:
unsigned long long x = 40000 * 100000;
You have to either do it in steps (like above) or cast one of the literals:
unsigned long long x = (unsigned long long) 40000 * 100000;
I may make a video on this topic as it's kinda confusing at first glance
Wonderful explaination ❤️
But, Could you please explain that line when you said something like that "This loop will goes to zero"
Please 🙏
I guess you're referring to the overflow that can be present when using size_t (or other unsigned integer types). Basically:
for (unsigned char i = 0; i < 256; i++) {
// This loop will forever execute
}
That's just because, in this case, an unsigned char can only store numbers between 0 and 255 (inclusive), so, when i is 255 and we increment it by 1, it goes back to 0 due to what we call an overflow
This is probably one of the best explanation of size_t
so you can still get elemets out of the array using array[i] even though i is size_t and array is integer type?
Yes, that is correct
Great video, super helpful!
so what is size_t?
Just an unsigned number used for dealing with lengths in the standard library
what about ssize_t, size8_t, size16_t. Please explain.
It's actually very simple. They are the same as size_t just they are of 8 bits and 16 bits respectively. ssize_t is signed (meaning it can retain negative numbers). I might make a video on this in the future
that's not the whole truth about size_t
What do you think it's missing?
@CodeVault What u're a saying in the video is not wrong, at all, but it's missing the point, the reason for size_t to exist. I'll try to explain. Size_t as it's name says it's the type wich represent the size (in bytes ofc), as you have shown in the video it's used in function like strlen and also sizeof as the return type; but the real reason to have a type defined for size is compatibility. The point of size_t is to be able to represent the maximum size of an object, witch ipotetically could occupy the whole ram, and since there're different types of architectures it has to account for that. What i mean with that? Let's say you're working on a 32 bit arch, that's a 32bit AddressBus, witch can address at max 2^32 bytes (not counting for sectors, for simplicity) you have to be able to represent the maximum size of an object occupying 2^32 bytes of memory, in a 64bit arch you have to be able to represent the size of a 2^64 bytes object (witch is huge); if you were to write your code using a long int instead of size_t on a 32b arch and then use your app on a 64b arch you would get in trouble, since an object could be many times larger that you expected. When you went and checked the definition for size_t, what could be noticed is that it has different definitions for architecture. Think it through, it's kinda logic, it has to be like that. In short, size_t needs to be able to represent the maximum size of anything based on the architecture it's been used in. Hope i made it clear, i'm not as good at explaining things and english is not my language.
edit: and also i forgot to mention, that's why you should use it as an iterator in combination with function witch returns size_t,; an int could be not enough and it might cause problems.
@@thecriminal87 I understand what you mean. Thanks for the explanation. In retrospect this video is lacking this explanation of a fundamental aspect of size_t. I think I'll make another video explaining this properly
such a great cheeks..
Thanks for sharing
I've become a fan of u man...
Are u there on linked in
I don't really use it
Wow :0
which ide is this
This is Visual Studio Community 2019... although, nowadays I use Visual Studio Code since it's more lightweight
*My friend it's JJJJJJJJR NOT ggggggggr .....INTEJJJJJJJJJR NOT INTEGGGGGGGR* 👍
Haha, I didn't notice I've been pronouncing it wrong the whole time!
Sorry but you speek heavily unclearly. 0:24 - you say what i want to do is "etari toverit"... for what.... just want to "etari toverit". What does "etari toverit" mean?
Sorry about my accent, I know it's sometimes an issue :D
What I said was: "Iterate over it"
@@CodeVault You definitely speak clearly.. not sure what this guys on about lol