Application of connection function strcat (simple explanation) in C + +

Source: Internet
Author: User
Tags function prototype

A learning brother asked me how to connect two characters, think of java/python inside can be directly connected with +, but there is no such a convenient way to do?

The answer is that there is a magical function called strcat in the String.h Library of C, which can do this. Let's start with the explanation below ~ ~ ~

At this point we may want to know what its prototype consists of:

extern Char *strcat (charconstchar *src);

As we can see, the prototype of the function is a pointer to two char types, which is defined in Chinese as follows:

char * strcat (target string, source string ); //Appends a copy of the source string to the destination string, terminates the null character in the destination string Fu Yuyuan The first character of the string, and joins the two strings to form a new string that contains a null char at the end.

In C, the function prototype exists in the <string.h> header file

Parameter definition

    • dest --points to the target array, which contains a C string and is sufficient to hold the appended string.
    • src --points to the string to append, which does not overwrite the target string.

The function returns a pointer to the final target string dest

As an example:

#include <stdio.h>#include<string.h>intMain () {Chard[ -] ="Goldenglobal"; Char* s ="View";    strcat (d,s); printf ("%s", D);    GetChar (); return 0;}

The printing results are as follows:

Let me give you an easy-to-understand example:

#include <stdio.h>#include<string.h>intMain () {Charstr[ the]; strcpy (str,"these"); strcat (str,"Strings"); strcat (str," is"); strcat (str,"concatenated.");  Puts (str); return 0;}

The printing results are as follows:

These strings is concatenated.

Application of connection function strcat (simple explanation) in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.