The difference between sizeof and strlen

1. sizeof is an  operator, while strlen is a library function.

2. The parameter of sizeof could be data type or variable, while strlen can only have char* as parameter.

3. The sizeof is calculated during the compile process, while strlen is caculated during the executing time.

4. sizeof returns the size of the memory space the data occupies, while strlen returns the exact length of the string.

5. When use array as a parameter, sizeof return the size of the array in terms of byte, while strlen returns the length of the string(it is the same as to pass the pointer to strlen).

This entry was posted in C++. Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s