Strlen() function example program in C C++

Coding in C

#include<stdio.h>
#include<string.h>
int main()
{
    char name[20];
    int len;
    printf("Enter name : ");
    scanf("%s",&name);
    len=strlen(name);
    printf("Length = %d",len);
    return 0;
}

Coding in C++

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char name[20];
    int len;
    cout<<"Enter name : ";
    cin>>name;
    len=strlen(name);
    cout<<"Length = "<<len;
    return 0;
}

Output

Strlen() function example program in C C++

Published by

admin

I am a computer teacher, programmer and web developer