- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between strlen() and sizeof() for string in C Program
As we know that in programming string can be defined as the collection of characters. Now for the requirement of finding how many characters are being used to create a string, C provides two approaches which are strlen() and sizeof().
As mentioned in above point both of these methods are used to find out the length of target operand but on the basis of their internal implementation following are some basic differences between both.
|1||Definition||strlen() is a predefined function defined in a Header file named string.h in C.||On other hand sizeof() is a Unary operator and not a predefined function.|
|2||Implementation||strlen is internally implemented as it primarily counts the numbers of characters in a string excluding null values, i.e returns the length of null terminating string.||While sizeof is implemented in such way that it calculates actual size of any type of data (allocated) in bytes (including the null values).|
|3||Null handling||strln excludes null and do not include it in the total computation of length of string.||On other hand sizeof doesn't care about the values of variable and compute actual size of any type of data (allocated) in bytes (including the null values).|
- Difference between strlen() and sizeof() for string in C
- What's the difference between sizeof and alignof?
- Difference between String and StringBuilder in C#
- Difference between string and char types in C++
- What is the difference between String and string in C#?
- C Program for Difference between sums of odd and even digits?
- Difference between String and StringBuffer.
- Difference between C++ string constants and character constants
- Write a C program demonstrating strlen library function
- Difference between Structure and Union in C Program
- C Program for the Difference between sums of odd and even digits?
- Sizeof operator in C
- Difference Between Character Array and String
- Difference between Relational operator(==) and std::string::compare() in C++
- Difference between string and StringBuffer in Java.