Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Array Count

Array Count

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmbiguousName
    wrote on last edited by
    #1

    hello guys... I have this array which has 5 elements in it like this.

    int arr[] = {1,2,3,4,5};

    Now how do I find the length of this array? thnx

    C H D S A 5 Replies Last reply
    0
    • A AmbiguousName

      hello guys... I have this array which has 5 elements in it like this.

      int arr[] = {1,2,3,4,5};

      Now how do I find the length of this array? thnx

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Not completely sure what you mean, but try this: #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) and use it like: int my_array_len = ARRAY_LENGTH(arr);

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > //TODO: Implement signature here<

      1 Reply Last reply
      0
      • A AmbiguousName

        hello guys... I have this array which has 5 elements in it like this.

        int arr[] = {1,2,3,4,5};

        Now how do I find the length of this array? thnx

        H Offline
        H Offline
        Hans Dietrich
        wrote on last edited by
        #3

        Use the built-in macro: http://msdn.microsoft.com/en-us/library/ms175773%28v=vs.80%29.aspx[^]

        Best wishes, Hans


        [Hans Dietrich Software]

        1 Reply Last reply
        0
        • A AmbiguousName

          hello guys... I have this array which has 5 elements in it like this.

          int arr[] = {1,2,3,4,5};

          Now how do I find the length of this array? thnx

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          overloaded Name wrote:

          Now how do I find the length of this array? thnx

          The size of the array, or the number of elements?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

          1 Reply Last reply
          0
          • A AmbiguousName

            hello guys... I have this array which has 5 elements in it like this.

            int arr[] = {1,2,3,4,5};

            Now how do I find the length of this array? thnx

            S Offline
            S Offline
            Software_Developer
            wrote on last edited by
            #5

            Use sizeof(arr) / 4;

            #include <stdio.h>

            void main()
            {

            int arr\[\] = {1,2,3,4,5};
            

            int x = sizeof(arr)/4;
            printf("sizeof(arr) = %d \n", x );

            }

            1 Reply Last reply
            0
            • A AmbiguousName

              hello guys... I have this array which has 5 elements in it like this.

              int arr[] = {1,2,3,4,5};

              Now how do I find the length of this array? thnx

              A Offline
              A Offline
              abhishek biradar
              wrote on last edited by
              #6

              int main() { int a[] = {1,2,3,4,5}; printf("%d",sizeof(a)/sizeof(int)); getch(); }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups