unsigned int is not necessarily equivalent to size_t... size_t is guaranteed to be at least 16 bits wide, but in practice it is often much, much larger as it is the largest unsigned integer value that can be stored. Even unsigned long may not be equivalent to the range of values that size_t can store. :-)
@@PortfolioCourses I understood from the replies about, so basically size_t will adopt the size of the most possible value and is therefore equivalent of the INT_MAX macro, hope its correct. Thanks for replying.
doesnt size_t mean unsigned int? I thought in unsigned int, there are 32 bits, and the number is always greater than 0. so technically it can represent any number in 2^32 combinations of bit which is like 4 billion
I have seen alot of your videos and are helpful, I have a little problem how would I get computer serial Number. system("wmic get bios serialnumber>sn.txt"); And store it in an array of character and then print it on screen.? I really need help with that.
making a size_t variable does't have a lot of overhead? since I'm asking so many bytes from the computer as many as possible on one variable to likely don't use even half of them?
The exact size of size_t depends on the compiler/system. It could be as small as 2 bytes. But it's true that in a lot of situations where size_t is returned, for example by strlen(), we can use an int and it will work fine because the numbers we're working with just aren't big enough for it to matter in practice. :-)
@@PortfolioCourses with that being the case, I should only use size_t when declaring a function that works with arrays and such to make it work in more scenarios but not for regular usage, right? And thanks for the answer and the vid.
Yes. Though to be honest with how much memory modern computers have, even using it "regularly" is OK. Really any scenario where we could have large enough numbers to justify size_t is where it makes sense to use size_t, I would say. :-)
On some compilers unsigned long will be able to store numbers as large as size_t, but interestingly it’s not guaranteed to be the case: stackoverflow.com/questions/15637228/what-is-the-downside-of-replacing-size-t-with-unsigned-long. Sometimes it may need to be unsigned long long for example.
@@PortfolioCourses interesting. Ive been using C compilers since TurboC for dos in 1987 and all the later Borland products and unsigned long has always been a 4 byte integer. And multiple compilers for PIC and embedded too. Char=byte, short=2byte, long=4byte Uint32 and Sint32 is probably the best way to say it which ie standard most of the newer embedded C compilers.
@@wizrom3046 Makes sense! I've found C is filled with lots of little things like this where something is supported 95-99% of the time as a convention by compilers but is not technically part of the C standard.
Thanks for the explanation, you see this in a lot of production code but hardly ever mentioned in C books.
You're welcome! 🙂
you are the best really C videos tutorial 💙❤️❤️❤️. I love your channel from Egypt
Thank you so much Mohammad! :-D
What stops me from using unsigned int instead of size_t?
unsigned int is not necessarily equivalent to size_t... size_t is guaranteed to be at least 16 bits wide, but in practice it is often much, much larger as it is the largest unsigned integer value that can be stored. Even unsigned long may not be equivalent to the range of values that size_t can store. :-)
@@PortfolioCourses I understood from the replies about, so basically size_t will adopt the size of the most possible value and is therefore equivalent of the INT_MAX macro, hope its correct. Thanks for replying.
You're welcome! :-) INT_MAX is the maximum value of an int. SIZE_MAX is the maximum value of size_t.
@@PortfolioCourses oops, sorry yea meant that :) Thanks for the swift responses.
@@MadpolygonDEV No problem! 🙂
thank you so much for this tutorial, you are the best
Weldone
Appreciate you're efforts.
Can you please do video on using malloc to allocate memory to a two dimensional array?
Thanks Olamide! That's definitely a topic that's on my "todo list". 🙂
for an int of 2 bytes the range should be -32,768 to 32,767 right ?
That sounds right as 2^16 = 65536 possible numbers. :-)
doesnt size_t mean unsigned int? I thought in unsigned int, there are 32 bits, and the number is always greater than 0. so technically it can represent any number in 2^32 combinations of bit which is like 4 billion
I have seen alot of your videos and are helpful,
I have a little problem how would I get computer serial Number.
system("wmic get bios serialnumber>sn.txt");
And store it in an array of character and then print it on screen.?
I really need help with that.
making a size_t variable does't have a lot of overhead? since I'm asking so many bytes from the computer as many as possible on one variable to likely don't use even half of them?
The exact size of size_t depends on the compiler/system. It could be as small as 2 bytes. But it's true that in a lot of situations where size_t is returned, for example by strlen(), we can use an int and it will work fine because the numbers we're working with just aren't big enough for it to matter in practice. :-)
@@PortfolioCourses with that being the case, I should only use size_t when declaring a function that works with arrays and such to make it work in more scenarios but not for regular usage, right? And thanks for the answer and the vid.
Yes. Though to be honest with how much memory modern computers have, even using it "regularly" is OK. Really any scenario where we could have large enough numbers to justify size_t is where it makes sense to use size_t, I would say. :-)
Bravo! Just a question. why can't we just use unsigned int data type instead of size_t?
size_t will store the largest unsigned numbers possible, but unsigned int may not be able to store numbers that are as large.
@@PortfolioCourses unsigned long does.
It is my preferred data type unless I specifically need signed math.
On some compilers unsigned long will be able to store numbers as large as size_t, but interestingly it’s not guaranteed to be the case: stackoverflow.com/questions/15637228/what-is-the-downside-of-replacing-size-t-with-unsigned-long. Sometimes it may need to be unsigned long long for example.
@@PortfolioCourses interesting. Ive been using C compilers since TurboC for dos in 1987 and all the later Borland products and unsigned long has always been a 4 byte integer. And multiple compilers for PIC and embedded too. Char=byte, short=2byte, long=4byte
Uint32 and Sint32 is probably the best way to say it which ie standard most of the newer embedded C compilers.
@@wizrom3046 Makes sense! I've found C is filled with lots of little things like this where something is supported 95-99% of the time as a convention by compilers but is not technically part of the C standard.
You might want to do a follow up on what is the signed equivalent of size_t. (Hint: it is not off_t)
Is there a universal equivalent, and if so what is it? long long int? ssize_t is POSIX so it's not truly universal.
@@PortfolioCourses I’d suggest prtdiff_t.
TLDR: t_size is just unsigned int, which is 4 bytes long.