#include <stdio.h>
int main() {
char str[] = "Hello, world!";
char *ptr;
ptr = str;
while (*ptr != '\0') {
printf("%c", *ptr);
ptr++;
}
return 0;
}
Hello, world!
str
that contains the string "Hello, world!
". ptr
and initializes it to point to the first character of str
.while loop
to iterate through each character in str
by dereferencing the pointer ptr
to get the value pointed to by ptr
, printing the value using printf
, and incrementing the pointer to point to the next character in the array. The loop continues until the null character \0
is encountered, indicating the end of the string.