Like Tree3Likes
  • 3 Post By rags_to_riches

UBound in c

This is a discussion on UBound in c within the C Programming forums, part of the General Programming Boards category; Is there any way of writing VB ubound(returns the index of the last element in the array) to c instead ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    33

    UBound in c

    Is there any way of writing VB ubound(returns the index of the last element in the array) to c
    instead of using sizeof operator
    int arr[20];
    printf("%d",sizeof array/sizeof(int));
    how to write using queue?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    As in you're implementing a queue? Then keep track of the start and end of the queue, or use a linked list where you track the tail.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    You really should consider spending less time trying to convert some VB code and more time learning the C language.
    qny, Salem and laserlight like this.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,295
    Assuming you're working with an array, the technique sizeof(array)/sizeof(*array) is the usual technique.

    If you're working with a pointer rather than an array (and that includes passing an array to a function) there is no way in C. When an array name is converted to a pointer, that pointer is associated with no information about the size of the original array. There is therefore no way to extract such information.

    As laserlight suggested, if you're implementing a queue, then your implementation of the queue needs to do bookkeeping to keep track of the required length.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21