Linked Questions
332 questions linked to/from How to find the size of an array (from a pointer pointing to the first element array)?
44
votes
7
answers
58k
views
C sizeof a passed array [duplicate]
Possible Duplicate:
How to find the sizeof( a pointer pointing to an array )
I understand that the sizeof operator is evaluated and replaced with a constant at compile time. Given that, how can a ...
25
votes
4
answers
118k
views
Find malloc() array length in C? [duplicate]
Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
I'm learning how to create a dynamic array in C, but have come across an issue I can't figure out.
If I use the code:
...
21
votes
5
answers
70k
views
How to get the length of an array from a pointer? [duplicate]
I'm having trouble finding the length of an pointer array. Let's say I have:
char array[40] = "hello"; // size 40
int length = sizeof array / sizeof array[0]; // no problem returns 40
//How do I get ...
3
votes
3
answers
28k
views
length of dynamic array in c++ [duplicate]
Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
I declared a dynamic array like this:
int *arr = new int[n]; //n is entered by user
Then used this to find length of ...
4
votes
5
answers
17k
views
How to find the size of dynamic array [duplicate]
Is there any way I could find how much bytes are allocated for RandomArray in this code
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *RandomArray;
int n;
...
0
votes
4
answers
813
views
how can i know the number of elements in array [duplicate]
i run the following code but it kept printing "4"
why its printing "4" and not "12"? and can I use malloc and then sizeof?(if i can then how)
#include<stdio.h>
int main()
{
int arr1[3]={1,...
3
votes
2
answers
1k
views
Why size of int pointer is different of size of int array? [duplicate]
Lets be the following code:
int x;
int *p = &x;
int t[3];
Then sizeof returns:
sizeof(x) -> 4
sizeof(p) -> 8
sizeof(t) -> 12
I suppose that sizeof(t) is the result of 3 * sizeof(int).
...
2
votes
2
answers
14k
views
length of char pointer c++ [duplicate]
Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
When declaring a char pointer using malloc for example. is there a way to determine the allocated length.
Example, if I ...
1
vote
2
answers
17k
views
c print array length [duplicate]
as part of a larger task I'm trying to print the length of an array in C, i.e how many elements are in an array. The array is an array of doubles, and I want to print a single integer which is how ...
0
votes
4
answers
2k
views
Find size of array pointed to by pointer [duplicate]
I have the below code:
int* d = (int*) malloc(100 * sizeof(int));
cout<<"size of d which is pointer is: " << sizeof(d)<<endl;
I know that sizeof outputs 4 as d is a ptr. But, ...
0
votes
1
answer
4k
views
C++ Size of char* buffer [duplicate]
Is there a way to determine the size of a char[] buffer via a char* pointer in C++? I'm using C++98.
The following lines of code all print out '8' (essentially sizeof(char*)). However I'm looking for ...
1
vote
5
answers
732
views
How does a C/C++ compiler automatically deduce array length for certain C function calls? [duplicate]
Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
In the first call to strcpy_s the compiler can deduce the array length, but in the second call the array length has to be ...
1
vote
3
answers
3k
views
C++ array size is always 4 [duplicate]
Hi I have an array defined in my header filed
private:
Customer** customerListArray;
In my cpp file I set it as following,
customerListArray = new Customer* [data.size()];
cout << "arr ...
1
vote
3
answers
3k
views
sizeof operator returns size of pointer instead of array [duplicate]
I'm a little confused when I run the code below:
int Maxi(int A[])
{
return sizeof(A)/sizeof(A[0]);
}
int main()
{
int A[5] = {1,2,3,4,5};
print("%d \n", Maxi(A));
return 0;
}
And I ...
2
votes
3
answers
206
views
Size of array defined with new? [duplicate]
Is there a function (that could be written) which allows to know the size of an array defined with new:
int *a=new int[3];
*a=4;
*(a+1)=5;
*(a+2)=6;
Thanks!