A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to print a string character by character using pointer
Q:

C program to print a string character by character using pointer

0

C program to print a string character by character using pointer

In this C program, we are going to learn how to read and print (character by character) a string using pointer?

Here, we have two variables, str is a string variable and ptr is a character pointer, that will point to the string variable str.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program

/*C program to print a string using pointer.*/
#include <stdio.h>
int main()
{
    char str[100];
    char *ptr;
     
    printf("Enter a string: ");
    gets(str);
     
    //assign address of str to ptr
    ptr=str;
     
    printf("Entered string is: ");
    while(*ptr!='\0')
        printf("%c",*ptr++);
         
    return 0;
}

Output

Enter a string: This is a test string.
Entered string is: This is a test string.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now