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);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s