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
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.
---> 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
char a="solo learn"
It will give output as: 10
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.
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..!!😉
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.