C++ Program to Count String Length Using Pointers

In this program, you will learn to count the 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
using namespace std;

int main()
    char str[10], *ptr;
    int len = 0;
    cout<<" Enter the string: ";
    cin>> str;
    ptr = &str[0];

    while(*ptr != NULL)

    cout<<" Length of string = " << len;
    return 0;
Enter the string: Programming
Length of string = 13