Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,844 questions

51,765 answers

573 users

How to use strlen with an array of pointers to strings in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    // Array of pointers to strings
    const char *strings[] = {"C programming", "general-purpose", "programming", "language"};
    int numStrings = sizeof(strings) / sizeof(strings[0]); // Calculate number of strings

    // Iterate through the array and print the length of each string
    for (int i = 0; i < numStrings; i++) {
        printf("Length of string \"%s\" is: %zu\n", strings[i], strlen(strings[i]));
    }

    return 0;
}


/*
run:

Length of string "C programming" is: 13
Length of string "general-purpose" is: 15
Length of string "programming" is: 11
Length of string "language" is: 8

*/

 



answered Nov 7, 2025 by avibootz
...