IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Strings - Discussion

@ : Home > C Programming > Strings > General Questions - Discussion

Read more:

"You cannot shake hands with a clenched fist."
- Indira Gandhi
7. 

Which of the following function is correct that finds the length of a string?

[A].
int xstrlen(char *s)
{
    int length=0;
    while(*s!='\0')
    {    length++; s++; }
    return (length);
}
[B].
int xstrlen(char s)
{
    int length=0;
    while(*s!='\0')
        length++; s++;
    return (length);
}
[C].
int xstrlen(char *s)
{
    int length=0;
    while(*s!='\0')
        length++;
    return (length);
}
[D].
int xstrlen(char *s)
{
    int length=0;
    while(*s!='\0')
        s++;
    return (length);
}

Answer: Option B

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


Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!