#include <stdio.h>
int main() {
//56. Write a C program to print the address of character and the character of string using
//pointer.
printf("\t\tAddress Of Character\n");
printf("================================================\n\n");
char str[] = "Supreme";
char *ptr;
ptr = str;
printf("The string is: %s\n", str);
printf("\n");
while (*ptr != '\0') {
printf("The address of character %c is: %p\n", *ptr, ptr);
printf("The character is: %c\n", *ptr);
printf("\n");
ptr++;
}
return 0;
}
<stdio.h>
.main()
function begins.str
is declared and initialized with the string "Supreme".ptr
is declared.ptr
pointer is assigned the address of the first element of the str
array.printf()
.while
loop is used to iterate over each character in the str
array.printf()
function is used to print the address of the current character pointed to by ptr
using the %p
format specifier.printf()
function is used again to print the character itself using the %c
format specifier.ptr
pointer is incremented to point to the next character in the array.\0
) is reached, indicating the end of the string.main()
function returns 0, indicating successful program execution.