GeeksforGeeks » C/C++ Programming Questions

Sizeof dynamic array

(2 posts)
  1. Anonymous
    guest
    Posted 1 year ago #

    How can you find the sizeof a dynamically created array?

    Eg: int *arr = (int *)malloc(sizeof(int)*int);

    sizeof(arr) will give you 4 as arr pointer. Is there anything like finding the sizeof of int without using sizeof operator.

  2. piyush
    guest
    Posted 1 year ago #

    I don't think there is any standard way of doing so. If you need size later in code then you can store the size in one variable and use it.

    int size = sizeof(int)*int;
    int *arr = (int *)malloc(size);


Reply

You must log in to post.

RSS feed for this topic