Monday, May 24, 2010

C :Wat is the difference in using a strlen() and sizeof() function in the case of a string or character array?

Please explain with an example....

C :Wat is the difference in using a strlen() and sizeof() function in the case of a string or character array?
strlen() gives the length of the string whereas the sizeof() gives the size occupied by the variable.since character occupies only one byte,the sizeof() returns the total memory occupied by it whereas strlen() gives the present length of the char array.


eg:


char a[10]={'s','a');


sizeof(a) will return 10.


strlen(a) will return 2.








dear Raven,


Array implicitly doesn't mean it is a two dimensionsional thing.it can be n dimensional. for this example i've chosen a single dimensional array.
Reply:string length is one dimensional length only.


in an array you also have to define coloum size.


No comments:

Post a Comment