Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How exactly find out length of ADT vector in C which is type of uint64_t?

I am trying to find out how to find the length of an ADT array type of uint64_t in C.

The code I wrote:

char * uint64_t(char * uint64_t, const char *restrict sep);

int size = sizeof(uint64_t) / sizeof(uint64_t[0]);

printf("Size of  vektor:", %zu, sizeof(uint64_t[0]));

I am not able to change any variables because it is prohibited by its creator (my professor) of whole code I can only implement some functions.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You cannot find the size of an array passed as a pointer into a function.

The compiler has no way of knowing how big it is, either

  • pass in the length as an arg
  • have a sentinel value, 0, -1, MAX_INT etc

I have ignored the fact that your code very messsed up , I assume you are trying to do this

 void func(uint64_t *arr , const char *restrict sep){
    int size = sizeof(arr) / sizeof(arr[0]);
    printf("Size of  vektor: %d", size);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading