+ 6
What is the difference between sizeof() and strlen()
I didn't understand yet.
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
+ 7
The sizeof(name) will return 20 and the strlen(name) will return 7.
+ 6
Strlen counts chars until the first 0 or null terminator (\0) is encountered.
+ 4
sizeof will return the whole size of the array.
strlen will return the number of initialized elements.
+ 4
Thanks a lot brother 💛
+ 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
+ 2
If I write......name[20]="sanjeev";
then,what is the value of sizeof() and strlen()
+ 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
+ 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.
+ 1
Sizeof() =20 and strlen() =7
+ 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
+ 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.
+ 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!👍
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
0
Strlen is a string function it gives u length of a string
Sizeof gives u the size of datatype
0
tx