Sunday, September 25, 2011

To find the length of string litteral or char array, We can use sizeof than strlen

sizeof is evaluated by the compiler where as strlen is evaluated at runtime.
Examples 1. int len = sizeof(“akamai”) - 1;

2. Char a[] = “akamai”; int len = sizeof(a) - 1;

3. Char *a = “akamai”; don’t use sizeof, please use strlen(a);

No comments:

Post a Comment