Strcpy() function example program in C C++

Strcpy() function example program in C C++

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

Strcpy() function example program in C

#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20],str2[20];
    printf("Enter a string   : ");
    scanf("%s",&str1);
    strcpy(str2,str1);
    printf("Value of string1 : %s\n",str1);
    printf("Value of string2 : %s\n",str2);
    return 0;
}

Strcpy() function example program in C++

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[20],str2[20];
    cout<<"Enter a string   : ";
    cin>>str1;
    strcpy(str2,str1);
    cout<<"Value of string1 : "<<str1<<endl;
    cout<<"Value of string2 : "<<str2<<endl;
    return 0;
}

Output of Strcpy() function example program in C C++

Strcpy() function example program in C C++

Some other string function examples in C C++

  1. String input-output without space
  2. String input-output with space
  3. Strlwr() function example program
  4. Strupr() function example program
  5. Strlen() function example program
  6. Strrev() function example program
  7. Strcat() function example program
  8. Strcmp() function example program
  9. String and Pointer
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer