+ 29
1st one will return the length of string, i.e., strlen, which is an inbuilt function of string.h which returns the length of string passed as a parameter.
In 2nd, there's "sizeof()" functions which returns the total size occupied by any variable or in this case, strings!
In 3rd, there's also "sizeof()" function but there's a pointer being passed on as parameter which basically doesn't make any difference because the arrays or strings, are always being passed as reference!
+ 20
strlen() is used to know length of string
+ 12
I think the first one (using strlen()).
sizeof1, returns the occupied size in bytes.
sizeof2, the size of the memory address (4 bytes on 32 bit machine)
+ 11
@Immortal ohhhk! my bad!😐👍
+ 11
First one returns the number of characters in a string excluding null terminator.
Second one returns the total length of a string including null terminator.
The third one returns the length of content present in pointer. We knew that pointer holds address of another variable then, the number of digits in address number is returned.
Example :if address is 4532, 4 is returned.
+ 10
strlen() function takes a string as an argument and returns the number of characters in it. i.e. The length of characters. The sizeof() is an operator that returns the size of the datatype in bytes in a specific computer.
+ 9
the first one will give you the string length
the second one will give you the actual string length will null ending .
the third one will give you the size of pointer i.e4 bytes
+ 9
strlen(arr) gives the number of characters present which in this case are 10(Sololearn!)
sizeof(arr) gives the occupied size ...which in the case of the current array is 11 (Sololearn!\0)...implicitly placed terminator
And sizeof(ptr) gives the size of the pointer which holds the address of the array
(I have no idea how that is 4 btw)
+ 9
Note that sizeof isn't an actual function call, it's a compiler builtin that translates the evaluation of the argument into an integer constant. This means you cannot get the sizeof anything that is heap (dynamically) allocated; you'll get the pointer type size instead of the allocation size.
http://en.cppreference.com/w/cpp/language/sizeof
+ 9
first one
+ 8
ohhh 😘
+ 5
The first printf () statement prints out the
length of the character array which is 10
because of the strlen function.
Next printf() prints the sizeof(arr) , the number of bytes in the character array
called arr , the total bytes in memory including the end of string marker '\0' , which
is 11 bytes, because sizeof computes
the size of the variable or datatype.
Lastly sizeof(ptr) returns the number
of bytes of the size of the pointer ptr
occupies in memory , which is 4 bytes.
+ 4
I actually learned quite a bit reading through these posts regarding your question!
+ 4
1st one
+ 3
first one
+ 3
strlen: return the length of a buffer until the first NUL byte is read (undefined result if the buffer does not contain a NUL byte; see man 3 strlen)
sizeof1: absolute size of a stack/static allocated array(!) including NUL bytes (used for binary buffers e.g. shellcode, encrypted data; absolute size equals sizeof(datatype)*array_length)
sizeof2: virtual address length (equals sizeof(long) on x86/x64 systems)
+ 3
The function strlen (char *) returns the length of the string(character array) up to but not including
the terminating null ('\0'), that is it does not
count the '\0' but uses terminating null to
know where the string ends. For example
char hi []="hello world" ;
total bytes of character array is string length + '\0' which is
12 bytes. But strlen (hi) is 11 characters only.
+ 2
in short
strlen()wll always return what you want it`s builts to count all non_null characters in a c-string
+ 1
first one will print that
+ 1
first one because it is built=in function of string which will get accurate length of string without adding any null character at end.
sizeof passed with direct array will add null character in last.
sizeof function again passed with ptr will print memory occupied by ptr.