size_t Type | C Programming Tutorial

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 31

  • @chrisray9653
    @chrisray9653 2 роки тому +2

    Thanks for the explanation, you see this in a lot of production code but hardly ever mentioned in C books.

  • @mohammadahmedragab837
    @mohammadahmedragab837 2 роки тому +6

    you are the best really C videos tutorial 💙❤️❤️❤️. I love your channel from Egypt

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

    What stops me from using unsigned int instead of size_t?

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

      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. :-)

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

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

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +2

      You're welcome! :-) INT_MAX is the maximum value of an int. SIZE_MAX is the maximum value of size_t.

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

      @@PortfolioCourses oops, sorry yea meant that :) Thanks for the swift responses.

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

      @@MadpolygonDEV No problem! 🙂

  • @Moon-hh1sh
    @Moon-hh1sh 3 місяці тому

    thank you so much for this tutorial, you are the best

  • @D_Ladybug
    @D_Ladybug 2 роки тому +2

    Weldone
    Appreciate you're efforts.
    Can you please do video on using malloc to allocate memory to a two dimensional array?

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

      Thanks Olamide! That's definitely a topic that's on my "todo list". 🙂

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

    for an int of 2 bytes the range should be -32,768 to 32,767 right ?

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

      That sounds right as 2^16 = 65536 possible numbers. :-)

  • @awekeningbro1207
    @awekeningbro1207 9 місяців тому

    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

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

    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.

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

    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?

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

      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. :-)

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

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

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

      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?

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

      size_t will store the largest unsigned numbers possible, but unsigned int may not be able to store numbers that are as large.

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

      @@PortfolioCourses unsigned long does.
      It is my preferred data type unless I specifically need signed math.

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

      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.

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

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

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

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

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

    You might want to do a follow up on what is the signed equivalent of size_t. (Hint: it is not off_t)

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

      Is there a universal equivalent, and if so what is it? long long int? ssize_t is POSIX so it's not truly universal.

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

      @@PortfolioCourses I’d suggest prtdiff_t.

  • @Andrii87
    @Andrii87 9 днів тому

    TLDR: t_size is just unsigned int, which is 4 bytes long.