C program to copy a string using pointers is simple program to Copy string using pointers.
In this tutorial we are going to see what is pointers, String copy in c, how to copy string using pointer and program to copy string using pointers.
First we will see pointers in c
What is pointers in c
Pointer is a variable which stores address of another variable.
String : string is a collection of character. 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 base address of string temporary variable and read the string stored at base address and print it.
Note : To copy string using pointer we copy Base address of string to pointer variable.
Concept you need to know from c
- Basic input output
- Pointers in c
- String in c
Algorithm to copy string using pointers
- Declare variable
- Take string input
- Copy base address to pointer variable
- Read and print string stored from address
C program to copy a string using pointers
printf("Enter a string\n");
t=s;//copying base address of string
printf("\nCopied string =%s ",s);
1. Start writing with main function
2. Declare variable
s => to store string
t => pointer variable.
3. Take string input from user
=> s = tech
4.Copy base address to pointer variable
t = s
5. Read value at address till end
=> this will read string tech one by one
6. Print string