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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:46:16+00:00 2026-06-19T00:46:16+00:00

This is probably going to be a pretty basic question but I’m confused on

  • 0

This is probably going to be a pretty basic question but I’m confused on how to implement something like this.

For a class I’m taking on C I need to take two arrays that can vary in length and compare their elements in a separate function. (This function only takes the arrays as parameters, not their sizes) Any element that is in both arrays I need to put into another array and return that array (NOTE: each array is like a set in that no elements repeat in the same array). I have looked into how I would implement this a little bit and here are some of the issues I’m running into.

  1. How do I know where the end of the array is?

    I think I saw that I might be able to do {0} as an element in the array for a null element. If this is true I don’t know what I would compare this element to in order to check for null.

  2. I think I’m supposed to pass pointers to the first element of the array because I don’t think C will let the values of an array be passed, but a little unsure.

    If I do pass the arrays as pointers, how can I access the arrays elements to get their data?

  3. When returning the array to the main function, how can I return the resulting function without the memory being cleared up?

    Should I make the resulting array global, or is there a better way of handling it?

Thanks in advance.

  • 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-19T00:46:17+00:00Added an answer on June 19, 2026 at 12:46 am

    Your question is a bit vague. It looks like you want to implement set intersection where you have two sets, represented by arrays, and the output is another array implemented as an array.

    1. How do I know where the end of the array is?

    In C, there is no way to tell. If you cannot pass the length as a function then you will not be able to do a robust solution. It will need to be something similar to #2.

    2. I think I saw that I might be able to do {0} as an element in the
    array for a null element. If this is true I don’t know what I would
    compare this element to in order to check for null.

    You can add a null character, which is just the value 0. To check, you will need to compare to 0. I do not know what do each of your array elements consist of, but one thing to watch of for is that none of those value is allowed to be zero anymore since it is reserved as an end of array marker.

    3. I think I’m supposed to pass pointers to the first element of the
    array because I don’t think C will let the values of an array be
    passed, but a little unsure.

    Yes. You will pass the pointed to first element, which in C is the array symbol.

    int A[10]; // pass A
    

    4. If I do pass the arrays as pointers, how can I access the arrays
    elements to get their data?

    Say you passed pointer A, you can access the elements by simple indexing as A[i], to grab the element i.

    5. When returning the array to the main function, how can I return the resulting function without the memory being cleared up?

    In the function you are writing, you can malloc an array and pass a pointer to the array created by malloc. Malloce’d memory is not deleted when the function exits.

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

Sidebar

Related Questions

I feel like this is probably a pretty simple question, but this is my
This is probably a simple question, but I am pretty new to using Quartz.NET,
This is going to be a pretty dumb question, but heeeere we go: I
Probably missing something pretty obvious but I can't figure out what is going on.
This question is probably pretty stupid, but I'm new to C# and I'm not
Unfortunately this is going to be a pretty open-ended question, but I am at
This is probably going to sound like a sci-fi request, though – is there
This is probably going to be an easy thing but I am having a
You can probably see where I am going with this - but is there
This probably sounds like a terrible idea at first glance, but here is my

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.