Linked Questions

11 votes
9 answers
40k views

How can I get the size of a memory block allocated using malloc()? [duplicate]

Possible Duplicates: How can I get the size of an array from a pointer in C? Is there any way to determine the size of a C++ array programmatically? And if not, why? I get a pointer to a chunk of ...
AndreasT's user avatar
  • 9,595
2 votes
5 answers
16k 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; ...
Tanmay Deshpande's user avatar
3 votes
4 answers
15k views

how to iterate through an array without knowing the size in c [duplicate]

I have a pointer to an array in C which I would like to iterate through, but I don't know the size: int *array; I am unsure as to how I should proceed. I was thinking that I should probably try by ...
a_confused_student's user avatar
3 votes
3 answers
141 views

how can one get the size of an array via a pointer? [duplicate]

For the following scenario, how can I get the size (3) of the array a via the pointer c? What is the pattern for solving this sort of problems? struct struct_point { int x; int y; int z; }; ...
WIZARDELF's user avatar
  • 3,777
1 vote
5 answers
306 views

How can I get the size of a pointer of a segment of memory, mallocked by function "malloc" [duplicate]

Possible Duplicates: How can I get the size of an array from a pointer in C? Any tool to find size of memory allocated dynamically using malloc/realloc? How can I get the size of a pointer of a ...
StevenWang's user avatar
  • 3,699
0 votes
0 answers
511 views

I ask calloc to allocate memory for 10 chars, but it sizeof returns 8 [duplicate]

I'm asking calloc to assign the sizeof of 11 chars: someString = calloc(11, sizeof(char)); I'm then using printf to print out the size of someString obtained with sizeof. printf("the size of ...
Daniel's user avatar
  • 247
0 votes
2 answers
157 views

Finding the memory allocated in program? [duplicate]

Possible Duplicate: How can I get the size of an array from a pointer in C? How can I get the size of a memory block allocated using malloc()? void func( int *p) { // Add code to print ...
siddharth's user avatar
  • 599
2 votes
1 answer
66 views

Why isn't the dynamically allocated memory for an array declaration and a pointer to an array declaration the same in C? [duplicate]

Consider the following C code snippet: int main() { int *crr; int arr[] = {1, 2, 3, 45}; crr = (int *)malloc(sizeof arr); printf("%ld\n", sizeof arr); printf("%ld", ...
taurus05's user avatar
  • 2,506
-4 votes
1 answer
68 views

logical error related to malloc [duplicate]

Here is a code which I have written. I have got some logical error in it. typedef struct bigint_ { int signbit; int*ptr; } bigint; void print_bigint(bigint big_num); bigint shift_by_power_of_10(...
SasiKiran's user avatar
0 votes
0 answers
47 views

Get the length of an array with a pointer? [duplicate]

I am looking for a way to get the length of an array for the pointer address. An example: int *a = (int*)malloc(sizeof(int)*2);// will be an array. *(a+0) = 1; // values of the array *(a+1) = 2; ...
NumberTheory's user avatar
0 votes
0 answers
41 views

Size is 4, but it must be 400 [duplicate]

Following program: #include <stdio.h> #include <stdlib.h> int main() { int *array; array = malloc(sizeof(int)*100); for(int i=0; i<sizeof(array); i++) { printf("%d\n",...
bando's user avatar
  • 3
0 votes
0 answers
33 views

is there a way to find the size of array just using its corresponding pointer in given code? [duplicate]

#include <stdio.h> void array_print (int *A) { int count = sizeof(A); for (size_t i = 0; i < count; i++) { printf("%d",A[i]); } ...
gsmnit's user avatar
  • 1
11 votes
12 answers
29k views

Why does malloc allocate a different number of bytes than requested?

I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> int main(){ void *a, *b; a = malloc(16); b = malloc(16); ...
Quamis's user avatar
  • 11k
12 votes
5 answers
86k views

How to determine the size of an allocated C buffer? [duplicate]

I have a buffer and want to do a test to see if the buffer has sufficient capacity I.e. find number of elements I can add to the buffer. char *buffer = (char *)malloc(sizeof(char) * 10); Doing a ...
godzilla's user avatar
  • 3,045
8 votes
6 answers
44k views

how can i know the allocated memory size of pointer variable in c [duplicate]

I have faced some problem in this case can you please your ideas. main() { char *p=NULL; p=(char *)malloc(2000 * sizeof(char)); printf("size of p = %d\n",sizeof (p)); } In this program Its print the ...
RoCkStUnNeRs's user avatar

15 30 50 per page