What is size_t in C?

Поділитися
Вставка
  • Опубліковано 29 вер 2024
  • Check out our Discord server: / discord

КОМЕНТАРІ • 56

  • @kcvinu
    @kcvinu 3 роки тому +18

    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.

  • @katloverchad697
    @katloverchad697 4 роки тому +1

    Thanks for the thorough explanation!

  • @abhi1110
    @abhi1110 3 роки тому +2

    If you wear an earphone, when he types, you can feel some vibration !

    • @CodeVault
      @CodeVault  3 роки тому

      I know... I still need to figure out some sound settings for the microphone. It's a bit of an odd issue

    • @abhi1110
      @abhi1110 3 роки тому

      @@CodeVault yes man plz fix it. I was watching your video at night, and those vibration gave me horror vibes😂😂

    • @CodeVault
      @CodeVault  3 роки тому

      @@abhi1110 Do you know if the same thing happens with the more recent videos? I have tweaked it quite a bit since this video.

    • @cyberpolice3183
      @cyberpolice3183 3 роки тому

      I thought it was an earthquake

  • @coolcodingcat
    @coolcodingcat Рік тому

    strlen should be called before the loop, otherwise you got O(N^2) instead of O(N).

  • @kartikgehlot2524
    @kartikgehlot2524 4 роки тому +11

    Just continue what you are doing...
    be unique and simple....

  • @tahevol
    @tahevol 3 роки тому +3

    Great video. Keep them coming. Your English is fine. Ignore the haters.

  • @samuelrawlinson9339
    @samuelrawlinson9339 3 роки тому +5

    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!

  • @abrahamrodriguez6462
    @abrahamrodriguez6462 3 роки тому +3

    4:20 It would loop forever only if a

    • @CodeVault
      @CodeVault  3 роки тому

      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

  • @sminter7521
    @sminter7521 3 роки тому +2

    Thanks im studying C and my textbook just vaguely mentioned this so i needed some further explanation!

  • @coolcodingcat
    @coolcodingcat Рік тому +1

    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.

    • @CodeVault
      @CodeVault  Рік тому

      Nicely explained!

    • @coolcodingcat
      @coolcodingcat Рік тому

      I meant to say, might not match unsigned int, but unsigned with no type is an alias for unsigned int anyway.

    • @coolcodingcat
      @coolcodingcat Рік тому

      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.

  • @coolcodingcat
    @coolcodingcat Рік тому

    it wont go forever, even if strlen is max size_t, because you are comparing

  • @LBCreateSpace
    @LBCreateSpace 4 місяці тому

    Ty so much for making this

  • @laveeshtomar
    @laveeshtomar 2 роки тому +1

    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)

    • @CodeVault
      @CodeVault  2 роки тому

      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

    • @laveeshtomar
      @laveeshtomar 2 роки тому

      @@CodeVault I am sorry but i was not pointing out mistake. I was enjoying that sound XD. Video is perfect

  • @domc97
    @domc97 3 роки тому +1

    so basically its only imporant for efficiency but int works fine, thanks

    • @CodeVault
      @CodeVault  3 роки тому +6

      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.

    • @domc97
      @domc97 3 роки тому

      @@CodeVault thanks for the comment, knowing this it would make reading code so much easier. Also the non negative is a huge plus. Subscribed :)

  • @kartikgehlot2524
    @kartikgehlot2524 4 роки тому +1

    your typing speed is amazing in coding...

  • @PETERTRITSCH
    @PETERTRITSCH 2 роки тому +1

    Another very good course from a master!

  • @jarosawnewidomski1448
    @jarosawnewidomski1448 2 роки тому

    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!

    • @CodeVault
      @CodeVault  2 роки тому

      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

  • @manavroy7293
    @manavroy7293 2 роки тому

    Wonderful explaination ❤️
    But, Could you please explain that line when you said something like that "This loop will goes to zero"
    Please 🙏

    • @CodeVault
      @CodeVault  2 роки тому

      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

  • @ShubhamMishra-mz4zw
    @ShubhamMishra-mz4zw Рік тому

    This is probably one of the best explanation of size_t

  • @jonashart5196
    @jonashart5196 2 роки тому

    so you can still get elemets out of the array using array[i] even though i is size_t and array is integer type?

  • @road2grandchamp238
    @road2grandchamp238 Рік тому

    Great video, super helpful!

  • @kulwantbhambra1
    @kulwantbhambra1 Рік тому

    so what is size_t?

    • @CodeVault
      @CodeVault  Рік тому +1

      Just an unsigned number used for dealing with lengths in the standard library

  • @jakepanda209
    @jakepanda209 2 роки тому

    what about ssize_t, size8_t, size16_t. Please explain.

    • @CodeVault
      @CodeVault  2 роки тому

      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

  • @thecriminal87
    @thecriminal87 7 місяців тому

    that's not the whole truth about size_t

    • @CodeVault
      @CodeVault  5 місяців тому +1

      What do you think it's missing?

    • @thecriminal87
      @thecriminal87 5 місяців тому

      ​ @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.

    • @CodeVault
      @CodeVault  5 місяців тому +1

      @@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

  • @marcutefys
    @marcutefys 2 роки тому

    such a great cheeks..

  • @mortenlund1418
    @mortenlund1418 2 роки тому

    Thanks for sharing

  • @smnk1073
    @smnk1073 3 роки тому

    I've become a fan of u man...
    Are u there on linked in

  • @adeled8833
    @adeled8833 4 роки тому

    Wow :0

  • @Code_Life_
    @Code_Life_ 3 роки тому

    which ide is this

    • @CodeVault
      @CodeVault  3 роки тому

      This is Visual Studio Community 2019... although, nowadays I use Visual Studio Code since it's more lightweight

  • @terry.chootiyaa
    @terry.chootiyaa 4 роки тому +5

    *My friend it's JJJJJJJJR NOT ggggggggr .....INTEJJJJJJJJJR NOT INTEGGGGGGGR* 👍

    • @CodeVault
      @CodeVault  4 роки тому +2

      Haha, I didn't notice I've been pronouncing it wrong the whole time!

  • @hansjurgendietrickmeinradw4519
    @hansjurgendietrickmeinradw4519 4 роки тому

    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?

    • @CodeVault
      @CodeVault  4 роки тому +9

      Sorry about my accent, I know it's sometimes an issue :D
      What I said was: "Iterate over it"

    • @johnprominski
      @johnprominski 3 роки тому +1

      @@CodeVault You definitely speak clearly.. not sure what this guys on about lol