c - How to find out size of array in function? -


this question has answer here:

is possible find out size of array in function without passing argument of size? this:

#include <stdio.h>  int length(const char* array) {   int r=sizeof(array); return r; }  int main() {   const char array[]="www.google.com"; int a; a=length(array); printf("%d\n",a); return 0;  } 

here result 8.

you can't that, have read sizeof operator, in program it's returning size of pointer, equivalent sizeof(char *).

you can length of string using strlen(), function requires array terminated special value '\0', means use +1 bytes store string.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -