Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:03:58+00:00 2026-05-27T09:03:58+00:00

How do I add two strings? I tried name = derp + herp; ,

  • 0

How do I add two strings?

I tried name = "derp" + "herp";, but I got an error:

Expression must have integral or enum type

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:03:59+00:00Added an answer on May 27, 2026 at 9:03 am

    C does not have the support for strings that some other languages have. A string in C is just a pointer to an array of char that is terminated by the first null character. There is no string concatenation operator in C.

    Use strcat to concatenate two strings. You could use the following function to do it:

    #include <stdlib.h>
    #include <string.h>
    
    char* concat(const char *s1, const char *s2)
    {
        char *result = malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
        // in real code you would check for errors in malloc here
        strcpy(result, s1);
        strcat(result, s2);
        return result;
    }
    

    This is not the fastest way to do this, but you shouldn’t be worrying about that now. Note that the function returns a block of heap allocated memory to the caller and passes on ownership of that memory. It is the responsibility of the caller to free the memory when it is no longer needed.

    Call the function like this:

    char* s = concat("derp", "herp");
    // do things with s
    free(s); // deallocate the string
    

    If you did happen to be bothered by performance then you would want to avoid repeatedly scanning the input buffers looking for the null-terminator.

    char* concat(const char *s1, const char *s2)
    {
        const size_t len1 = strlen(s1);
        const size_t len2 = strlen(s2);
        char *result = malloc(len1 + len2 + 1); // +1 for the null-terminator
        // in real code you would check for errors in malloc here
        memcpy(result, s1, len1);
        memcpy(result + len1, s2, len2 + 1); // +1 to copy the null-terminator
        return result;
    }
    

    If you are planning to do a lot of work with strings then you may be better off using a different language that has first class support for strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add two strings with snprintf but apparently i dont know what
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
Can i add two header text in Datagrid? My Requirement is to have two
I have Created a database in Sqllite Android Application and I tried to add
I have tried to find information about this but have come up empty handed:
I have two entities: Event and Comment. @Entity @Table(name = events) public class Event
I have two similar classes, that simply have a string name. I wanted to
Why is my enhanced loop not working? Vector<String> v = new Vector<String>(); v.add(one); v.add(two);
string str = one three; string::iterator it; string add = two ; Lets say
In the code below I use mpf_add to add the string representation of two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.