C program to copy a string using pointers is a simple program to Copy string using pointers.

What is pointers in c?
The pointer is a variable that stores address of another variable.
String: string is a collection of characters. The string has its base address.

What is Base address: A base address is an absolute address that acts as a reference point for other addresses.

How to copy string using pointers
Copy string using pointers: First, we take a string input. Then copy the base address of string temporary variable and read the string stored at the base address and print it.
Note: To copy string using pointer we copy the Base address of the string to a pointer variable.

Algorithm to copy string using pointers

  1. Declare variable
  2. Take string input.
  3. Copy base address to a pointer variable.
  4. Read and print string stored from address

C program to copy a string using pointers

#include<stdio.h>
main()
{
char s[25],*t;
printf("Enter a string\n");
scanf("%s",&s);
t=s;//copying base address of string
printf("\nCopying string\n");
while(*t!='
#include<stdio.h>
main()
{
char s[25],*t;
printf("Enter a string\n");
scanf("%s",&s);
t=s;//copying base address of string
printf("\nCopying string\n");
while(*t!='\0')
{
printf("Copying %c\n",*t);
t++;
}
printf("\nCopied string =%s ",s);
}
') { printf("Copying %c\n",*t); t++; } printf("\nCopied string =%s ",s); }

Output :

copy string using pointers

Write A Comment