About 3,050,000 results
Open links in new tab
  1. How to get number of elements in the array of pointers?

    Aug 27, 2018 · Then you should use a std::array<mystruct*, 2> m_arr;, the size of which you can access through m_arr.size(), and the address of the underlying native array you get with …

  2. C++ Smart Pointers and Arrays - C++ Stories

    Oct 25, 2021 · In the example, you see pointers to a single instance of Object or an integer. Similarly, if you want to have a pointer to an array of objects then you’re happy to do it in C++: …

  3. How can I find the number of elements in an array?

    Apr 24, 2012 · It is not possible to find the number of elements in an array unless it is a character array. Consider the below example: int arr[100]={1,2,3,4,5}; int size = sizeof(arr)/sizeof(arr[0]); …

  4. In C how to get number of items in array of pointers to char strings

    Dec 24, 2012 · You have a couple of options: Pass the number of items in the array. Set the last item to NULL so the code knows when it's reached the end. (This is kind of how C strings are …

  5. How to know how many elements there are in a pointer array?

    There is no way you can know the size of array passed to function. As array decays to pointer to first element. Compiler will treat. void print(char *arch[], int num) as void print(char **arch, int …

  6. How to find the number of elements in a pointer array?

    May 15, 2022 · What are the different ways to find the number of elements in a int array pointer which is allocated with malloc? int* a = malloc (...) You have to remember the size (e.g.) size_t …

  7. The number of elements in an array using pointers in C++

    Dec 20, 2016 · So, sizeof(P) depends only on compiler and OS platform (e.g. pointer can be 32-bit or 64-bit), but sizeof(A) depends on size of item (int may be not 32 bits) and NUMBER OF …

  8. C: finding the number of elements in an array[] - Stack Overflow

    Nov 2, 2010 · In C and C++ as soon as an array is passed to a function the array degenerates into a pointer. Pointers have no notion of how many elements are in the array they point to. A …

  9. shared_ptr in C++ - GeeksforGeeks

    Nov 12, 2024 · 1. Initialization using a New Pointer std::shared_ptr<T> ptr(new T()); std::shared_ptr<T> ptr = std::make_shared<T>(); 2. Initialization using existing Pointer …

  10. Arrays and Pointers in C++ - dummies

    When you declare an array, always try to put a number inside the brackets, unless you are writing a function that takes an array. When you use the extern keyword to declare an array, go …

Refresh