+ 6

What is the difference between sizeof() and strlen()

I didn't understand yet.

31st Oct 2019, 9:18 PM
Sanjeev Kumar
Sanjeev Kumar - avatar
17 ответов
+ 12
strlen() is used to get the length of an array of chars / string. sizeof() is used to get the actual size of any type of data in bytes
31st Oct 2019, 9:57 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 7
The sizeof(name) will return 20 and the strlen(name) will return 7.
31st Oct 2019, 10:09 PM
Avinesh
Avinesh - avatar
+ 6
Strlen counts chars until the first 0 or null terminator (\0) is encountered.
1st Nov 2019, 3:33 AM
Sonic
Sonic - avatar
+ 4
sizeof will return the whole size of the array. strlen will return the number of initialized elements.
31st Oct 2019, 10:13 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 4
Thanks a lot brother 💛
31st Oct 2019, 10:56 PM
Sanjeev Kumar
Sanjeev Kumar - avatar
+ 3
In this case, the function strlen() will return 7 and the function sizeof() will return 20. The character array can store only 19 characters, because the last one will always be a '\0'. The function strlen() counts the size of a string, and does not include the '\0'. Otherwise, the function sizeof() includes it. See the code: https://code.sololearn.com/cTLTobe16k33/?ref=app
1st Nov 2019, 5:02 PM
Jonas Ferraz
Jonas Ferraz - avatar
+ 2
If I write......name[20]="sanjeev"; then,what is the value of sizeof() and strlen()
31st Oct 2019, 10:00 PM
Sanjeev Kumar
Sanjeev Kumar - avatar
+ 2
Strlen() is used for getting size or length of arrays Sizeof() is used to get size of data types https://code.sololearn.com/cOUP85SNNd0A/?ref=app
2nd Nov 2019, 2:23 PM
Tanmay Gupta
Tanmay Gupta - avatar
+ 2
strlen() returns the actual character length of the string (not counting '/0'). (String.h) sizeof () works with all basic type of data (int, float...) and returns the number of bytes you allocated for that variable. (Stdlib.h) As 1 character = 1 bytes, the length of the string is the dimension you declared -1 and they will return the same value. I hope this is clear and right, I'm new to programming.
2nd Nov 2019, 4:55 PM
Elz
+ 1
Sizeof() =20 and strlen() =7
1st Nov 2019, 5:31 AM
Kaveri Talawar
Kaveri Talawar - avatar
+ 1
Example:: ---> sizeof() Is used to find the size of data type in bits 32 bit computer have sizeof(int) will give output:4 sizeof (float) will give output:4 sizeof(char) will give output:1 sizeof (double) will give output:8 strlen() is used to get the length of the array or string I mean that It returns the number of elements in the array or string as a number Example:: char a="solo learn" strlen(a) It will give output as: 10
2nd Nov 2019, 2:36 AM
Siva Naik Kethavath
Siva Naik Kethavath - avatar
+ 1
You can use strlen for getting the length of an string ( there is no concept of string its just pointer pointing to the first character of sequence of character and there is a terminating chracter. If there is a string which is of 4 characters then you will need 5 bytes to store why = char=1byte *4 + null terminating character) Now towards the main point - size of is used to know the size of data types like int , char , double , bool which has sizes 4bytes(depends on pc),1byte, 8bytes,1byte respectively.
2nd Nov 2019, 2:45 PM
Rahul Nagpure
Rahul Nagpure - avatar
+ 1
The function sizeof() is a unary operator in C language and used to get the size of any type of data in bytes. The function strlen() is a predefined function in C language.This is declared in "string.h" header file.It is used to get the length of array or string. Hope you might have got the answer..!!😉 Thanks!👍
5th Jan 2020, 12:39 PM
A.Sudheer Rajkumar
0
strlen() --> returns the no.of characters present in a given String including spaces in between. sizeof() --> returns the actual size of datatype used or it returns the size of array(if used). Make sure you run this code,it may help you little bit to have a clear idea on this topic. https://code.sololearn.com/cdCGgD7j64X5/?ref=app
2nd Nov 2019, 8:40 AM
A.Sudheer Rajkumar
0
Strlen is a string function it gives u length of a string Sizeof gives u the size of datatype
2nd Nov 2019, 11:35 AM
bhakti thakar
0
tx
2nd Nov 2019, 3:15 PM
AVENGERS TRAILER
AVENGERS TRAILER - avatar