C Programming - Strings - Discussion
Discussion Forum : Strings - General Questions (Q.No. 7)
7.
Which of the following function is correct that finds the length of a string?
Answer: Option
Explanation:
Option A is the correct function to find the length of given string.
Example:
#include<stdio.h>
int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
{ length++; s++; }
return (length);
}
int main()
{
char d[] = "IndiaBIX";
printf("Length = %d\n", xstrlen(d));
return 0;
}
Output: Length = 8
Discussion:
17 comments Page 1 of 2.
Shendu said:
1 year ago
It's a very good website for gathering the knowledge.
Also, it is helpful for the placement. Thanks all.
Also, it is helpful for the placement. Thanks all.
Harsh said:
3 years ago
@Ahmed;
Strlen gives output of string length excluding null character.
Strlen gives output of string length excluding null character.
Ahmed Shindy said:
3 years ago
"IndiaBix" length is 9 including the null termination character.
Am I right? Anyone, please clarify.
Am I right? Anyone, please clarify.
(1)
Abay said:
6 years ago
what do strleni(); do? Please explain.
Vivek ladhe said:
6 years ago
@Akshay.
strlen is a std library function.
xstrlen is a user-defined function.
strlen is a std library function.
xstrlen is a user-defined function.
Marcos said:
8 years ago
What exactly xstrlen() do than strlen()? Explain.
Devi achsah said:
8 years ago
I don't know exactly. But I can share I what know. In this program xstrlen is only the name of the function.
Akshay said:
9 years ago
What is the difference between strlen and xstrlen ?
If there is no any difference so, what is the significance of xstrlen in C programming?
If there is no any difference so, what is the significance of xstrlen in C programming?
Ali said:
9 years ago
Please explain this program in detail.
Harsh patil said:
9 years ago
The string we have stored in the char D[] in main function will be pass the to the xstrlen(d) function and it will be parsed by *s and length will be counted by length++. So we need to have length ++ and s++.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers