To access and print string elements, we can use loops and check for the '0' null character.
In the following example, we are using a 'while' loop to print the character 'str' for a string variable.
#include <stdio.h>
int main(void) {
//string variable
char str[6] = "Hello";
//pointer variable
char *ptr = str;
//print the string
while(*ptr != '\0') {
printf("%c", *ptr);
//move the ptr pointer to the next memory location
ptr++;
}
return 0;
}