Thread: Check if array is sorted

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Using size_t is the right thing to do, but feel free to use plain old int.

    'size_t' is just an appropriately sized unsigned integer that matches the processor's address space.

  2. #2
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    956
    Quote Originally Posted by hamster_nz View Post
    Using size_t is the right thing to do, but feel free to use plain old int.

    'size_t' is just an appropriately sized unsigned integer that matches the processor's address space.
    Not necessarily. size_t is a type that can hold the size of the largest supported object. For example, on ye olde x86 segmented memory system, size_t might be only 16 bits wide (no object can be larger than 64 KiB), even though a pointer might be 20 bits wide (for a whopping 1 MiB of addressable memory).

    size_t is an appropriate type to use when referring to object sizes (e.g., with malloc) or indexes into arrays, since size_t is guaranteed to be capable of indexing every possible location in an array.

  3. #3
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277
    Quote Originally Posted by christop View Post
    Not necessarily. size_t is a type that can hold the size of the largest supported object. For example, on ye olde x86 segmented memory system, size_t might be only 16 bits wide (no object can be larger than 64 KiB), even though a pointer might be 20 bits wide (for a whopping 1 MiB of addressable memory).

    size_t is an appropriate type to use when referring to object sizes (e.g., with malloc) or indexes into arrays, since size_t is guaranteed to be capable of indexing every possible location in an array.
    Interesting caveat. I wasn't aware there was a distinction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to check if an array of doubles is sorted?
    By Lina_inverse in forum C Programming
    Replies: 20
    Last Post: 10-06-2012, 03:12 PM
  2. How to detect if a array is sorted.
    By just_rookie in forum C++ Programming
    Replies: 14
    Last Post: 09-10-2012, 05:35 AM
  3. Selecting pivot in sorted array.
    By infantheartlyje in forum General Discussions
    Replies: 4
    Last Post: 10-14-2011, 09:43 AM
  4. how delete 1th element of a sorted array
    By vicky_4040 in forum C Programming
    Replies: 4
    Last Post: 10-11-2009, 06:12 AM
  5. finding max/min in a sorted array
    By Crcullen3916 in forum C++ Programming
    Replies: 9
    Last Post: 09-23-2008, 02:18 AM

Tags for this Thread