answersLogoWhite

0

The sizeof operator returns the total size, in bytes, of the given operand, whereas the strlen function returns the number of characters in the argument up to but not including the first null-terminator.

Consider a character buffer allocated 50 bytes to which you assign the string "Hello world". The sizeof operator will return 50, but the strlen function returns 11.

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

ReneRene
Change my mind. I dare you.
Chat with Rene
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: Difference between sizeof and strlen
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the output for the following C program include include void main(void) char str1 Hello world char str2 Hello world printf (d d d d sizeof(str1) sizeof(str2)strlen(str1) strlen(str2))?

What is the output for the following C program? include<stdio.h> int main (void) { char* str1 = "Hello world"; char str2[] = "Hello world"; printf ("%d, %d, %d, %d\n", sizeof(str1), sizeof(str2), strlen(str1), strlen(str2)); return 0; } Assuming sizeof (char*) is 4 bytes (implementation-defined) the output will be: 4, 13, 12, 12


Why use length function to find length of primitive data type array object?

There is no length function in C. You may have thought of sizeof or strlen. Perhaps.


How do you write c plus plus program to display size of the each data type?

The core if it would contain lines like these: printf ("sizeof (char)=%d\n" "sizeof (short)=%d\n" "sizeof (int)=%d\n" "sizeof (long)=%d\n" "sizeof (long long)=%d\n" "sizeof (size_t)=%d\n" "sizeof (void *)=%d\n" "sizeof (ptrdiff_t)=%d\n" "sizeof (va_list)=%d\n" "sizeof (intptr_t)=%d\n" , (int)sizeof (char) , (int)sizeof (short) , (int)sizeof (int) , (int)sizeof (long) , (int)sizeof (long long) , (int)sizeof (size_t) , (int)sizeof (void *) , (int)sizeof (ptrdiff_t) , (int)sizeof (va_list) , (int)sizeof (intptr_t) );


Difference between array and union?

All the members of the structure can be accessed at once,where as in an union only one member can be used at a time. Another important difference is in the size allocated to a structure and an union. for eg: struct example { int integer; float floating_numbers; } the size allocated here is sizeof(int)+sizeof(float); where as in an union union example { int integer; float floating_numbers; } size allocated is the size of the highest member. so size is=sizeof(float);


Write a c program to print the sizes and ranges of different data types in c?

#include<stdio.h> #include<conio.h> void main() { float f1,*Ptr1,*Ptr2; ptr1 = &fl; ptr2 = (&fl+1); printf("%u",(char *)ptr2-(char *)ptr1); getch(); }