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 8454615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:04:20+00:00 2026-06-10T12:04:20+00:00

So this is a homework assignment, there might be come constraints that are ridiculous

  • 0

So this is a homework assignment, there might be come constraints that are ridiculous but please bear with me. This is just a simple function but drawn out. I need to return a character array via assignment operator but it doesn’t seem to be working at all. I’ve tried pointers, but no luck.

#include <iostream>
using namespace std;

char* findMax(char*, char*);

int main()
{
    char aArray[50] = "Hello World",
        bArray[50] = "dlroW olleH",
        maxArray[50];

    maxArray[50] = findMax(aArray, bArray);

    cout << maxArray << " is the bigger of the 2 strings" << endl;
    return 0;
}

char* findMax(char* strA, char* strB){
    char* maxStr;

    if(strcmp(strA, strB) < 1)
        maxStr = strB;
    else
        maxStr = strA;

    return maxStr;
}

if I cout the return value of findMax() it does print out the value of bArray, but geting it into maxArray via assignment operator isn’t working at all.

  • 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-06-10T12:04:22+00:00Added an answer on June 10, 2026 at 12:04 pm

    There are two ways to do this. As written, maxArray is an array of characters. Arrays can’t be directly assigned to. Instead you need to copy each character one by one. You could do that with a loop, or by calling the strcpy standard library function.

    char maxArray[50];
    
    strcpy(findMax(aArray, bArray), maxArray);
    

    The other way is to change the declaration of maxArray to be a char *, a pointer. Pointers can be assigned to directly without having to loop or invoke a function.

    char *maxArray;
    
    maxArray = findMax(aArray, bArray);
    

    The difference between this and the first solution is subtle, but important. With char maxArray[50] you are actually allocating a third array of 50 characters, separate from aArray and bArray. This array has its own storage, its own 50 bytes of memory.

    In the second you don’t create a third array. You merely create a pointer which can point to other arrays already in existence. After the assignment, maxArray becomes an indirect reference to either aArray or bArray. It’s not a copy of one of those arrays, it points to one of them.

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

Sidebar

Related Questions

I know this sounds like a homework assignment, but it isn't. Lately I've been
This is in relation to a homework assignment but this is not the homework
I've just completed the coding section of simple homework assignment for my C++ class.
I had a homework assignment that asked for a function that uses direct recursion
I am working on this homework assignment and I am stuck on what I
Let me start by saying this is a homework assignment, I don't need any
First of all, this is a homework assignment. I'm trying to make some bubbleSort
This is part of a homework assignment. I've got several questions asking find the
(this is indirectly a part of a much larger homework assignment) I have something
Full disclosure : This is for a homework assignment. This is driving me nuts.

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.