Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Last Updated: Mar 27, 2024
Difficulty: Medium

wcscat() in CPP

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM


The article covers the implementation of wascat() method In C++, the wcscat() method copies a wide string and appends it to the end of another wide string. In the <cwchar> header file, the wcscat() method is defined. You can think it as a concatination method for wide characters.

There is a popular quote “Don’t talk, just show me the code!!” abiding by the words let see the implementation of the wcscat() in C++.

Also see, Literals in C, Fibonacci Series in C++

BreakDown of wcscat() method

The section discusses the detailed breakdown of the wcscat() method in C++.  It includes discussion of declaring the prototype, parameters of wcscat() and return value of the wcscat() method.

Prototype declaration wcscat()

wchar_t* wcscat(wchar_t* dest, const wchar_t* src);


The dest and src inputs are sent to the wcscat() method. This function appends a duplicate of src's wide character string to the end of dest's wide character string.

The first character of src replaces the null ending wide character at the end of dest, and the new character is also null terminated.

If the behaviour isn't defined,

1. The strings overlap.
2. The dest array is too small to accommodate the contents of src.

Parameters of wcscat()

dest: Pointer to a null terminating wide string to append to.
src: Pointer to a null terminating wide string that is to be appended.

Return value of wcscat()

The wcscat() function returns the dest pointer.

Also Read - C++ Interview Questions

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Program Implementation

Let us see the implementation of the method in code to get the better understanding of the subject:

#include <cwchar>
#include <clocale>
#include <iostream>
using namespace std;

int main()
   // setting the format to US ENG to utf8 file format
   setlocale(LC_ALL, "en_US.utf8");

   wchar_t dest[50] = L"\u0905 \u0906 \u0907 \u0908 ";
   wchar_t src[50] = L"\u0915 \u0916 \u0917 \u0918 ";

   wcscat(dest, src);
   wcout << "After processing by wcscat(): " << dest << endl;

   return 0;


After compiling and running the article in the terminal:

You can try and compile with the help of online c++ compiler.

Frequently Asked Questions

Which is faster memcpy or Memmove?

"Memcpy is more efficient than memmove," says the author. You're probably not performing the same thing when running the two functions in your situation. In general, only use memmove when absolutely necessary. When there's a good likelihood that the source and destination zones will overlap, use it.

What is the use of Memmove?

The method memmove() copies count bytes from source to dest. As if src were first put into a temporary array, this method permits copying across objects that may overlap.

What is the difference between memcpy and Memmove?

The memcpy() method copies a certain number of bytes from one memory to another. The memmove() method copies a given number of bytes from one memory to another or overlaps two memories.


The article extensively covers the implementation of wcscat() method in c++, we see the working of code.

Do upvote our blog to help other ninjas grow, and head over to our practice platform Coding Ninjas Studio to practise top problems, attempt mock tests, read interview experiences, and much more.

Happy Learning!

Topics covered
BreakDown of wcscat() method
Prototype declaration wcscat()
Parameters of wcscat()
Return value of wcscat()
Program Implementation
Frequently Asked Questions
Which is faster memcpy or Memmove?
What is the use of Memmove?
What is the difference between memcpy and Memmove?