C Program to Print Length of String Using Pointers

In this program, you'll learn to print length of string using pointers.



Source Code
#include<stdio.h>
int main()
{
    char str[20];
    char *cptr;
    int len = 0;

    printf("Enter the string\n");
    gets(str);

    cptr = &str[0];
    while(*cptr != NULL)
    {
        len++;
        cptr++;
    }
    printf("\nLength of string is = %d", len);
    return 0;
}
Output
Enter the string
Thank you!

Length of string is = 10