Related Articles
The length of a string using pointers
• Last Updated : 11 Jan, 2018

Write a program to find the length of a string using pointers .

Examples:

```Input : given_string = "geeksforgeeks"
Output : length of the string = 13

Input : given_string = "coding"
Output : length of the string = 6
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Prerequisite : Pointer in C

Approach Used : In this program we make use of * operator. The * (asterisk) operator denotes the value of variable . The * operator at the time of declaration denotes that this is a pointer, otherwise it denotes the value of the memory location pointed by the pointer. In the below program, in string_length function we check if we reach the end of the string by checking for a null represented by ‘\0’ .

 `// C++ program  to find length of string``// using pointer arithmetic.``#include ``using` `namespace` `std;`` ` `// function to find the length``// of the string through pointers``int` `string_length(``char``* given_string)``{``    ``// variable to store the``    ``// length of the string``    ``int` `length = 0;``    ``while` `(*given_string != ``'\0'``) {``        ``length++;``        ``given_string++;``    ``}`` ` `    ``return` `length;``}`` ` `// Driver function``int` `main()``{``    ``// array to store the string``    ``char` `given_string[] = ``"geeksforgeeks"``;``    ``cout << string_length(given_string);``    ``return` `0;``}`

Output:

```13
```
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.62737954,"math_prob":0.95958376,"size":1362,"snap":"2021-04-2021-17","text_gpt3_token_len":324,"char_repetition_ratio":0.18409425,"word_repetition_ratio":0.04255319,"special_character_ratio":0.2606461,"punctuation_ratio":0.116883114,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97680557,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-19T03:50:43Z\",\"WARC-Record-ID\":\"<urn:uuid:b6d1f067-9a3a-4a82-bea7-d6abbfe9240a>\",\"Content-Length\":\"83372\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fd0b3a2a-c7e6-466a-8597-416a62724825>\",\"WARC-Concurrent-To\":\"<urn:uuid:58e830f4-d3bc-4407-800f-e3a4069c767b>\",\"WARC-IP-Address\":\"23.62.230.194\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/length-string-using-pointers/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:MIOOP64JVZD2VPVN2WWUTGF3OGQWAQZ3\",\"WARC-Block-Digest\":\"sha1:LUTJBNI5OCPE35FKBMPG2YKZJPO3V66E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038863420.65_warc_CC-MAIN-20210419015157-20210419045157-00055.warc.gz\"}"}