string length without stdlib in c

Calculating String Length Without Standard Library in C:

#include <stdio.h>

int main() {
    char a[] = "Google.com";
    int i = 0;

    // Loop until null terminator is encountered
    while (a[i] != '\0')
        i++;

    printf("The string length is %d.", i);
    return 0;
}

Output:

The string length is 10.

In this C program, we manually calculate the length of the string without using any standard library functions. We iterate through the character array until we encounter the null terminator ('\0'), which marks the end of the string. We then print the length of the string based on the number of iterations.

If you have any further questions or need additional assistance, feel free to ask!

No comments: