C Program to Find String Length Using Pointers

In this program, you will learn to find length of string using pointers. The pointer is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. The size of the pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte.

Source Code
int length(char *);

int main()
    char *ptr, str[10];
    printf(" Enter the string: ");
    scanf("%s", str);
    ptr = &str[0];
    printf(" Length of string = %d", length(ptr));
    return 0;
int length(char *p)
    int count = 0;
    while(*p != NULL)
    return count;
Enter the string: Programming
Length of string = 13