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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:57:54+00:00 2026-06-13T16:57:54+00:00

I don’t have too much experience managing pointers, and other advanced functions but I

  • 0

I don’t have too much experience managing pointers, and other advanced functions but I was thinking if it is possible to make an algorithm to exchange the memory addresses between two elements of an array using pointers, instead copying and moving the value each time ( example while sorting ). Let me explain:

Imagine this array It has 10 elements unsorted, and I pretend to use bubble-sort to sort it (in any order), the typical way is to use a secondary variable to copy the elements and use it as bypass each time i find a smaller or greater number (depends on descending or increasing sorting).

            *----*----*----*----*----*----*----*----*----*----*
array[10] = | 45 | 21 | 32 | 48 | 32 | 22 | 47 | 10 | 11 | 12 |
            *----*----*----*----*----*----*----*----*----*----*
            ^----- Imagine this is 10000

The program realizes that the array[ 1 ] is smaller than the array[ 0 ], so the bubble-sort will exchange their values (this is the typical way) using a secondary variable as bypass.

                   *--------------* 
                   |              ^
                   |              |
            *--------------*--------------*----*----*----*----*----*----*
array[10] = |      45      |      21      | 32 | 22 | 47 | 10 | 11 | 12 |
            *--------------*--------------*----*----*----*----*----*----*
                   |              ^
                   |   *------*   |
                   *-->|BYPASS|---*
                       *------*

So isn’t possible to say something like exchange &array[0] and &array[1] addresses? So i avoid the secondary variable? In this case &array[1] = 10000; and &array[0] = 10004.

Thanks for your attention and all suggestions are allowed!

  • 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-13T16:57:55+00:00Added an answer on June 13, 2026 at 4:57 pm

    You can do this

     array[0] += array[1];
     array[1] = array[0] - array[1];
     array[0] -= array[1];
    

    and not use a third variable.

    An array is a contigious continuous memory space. You cannot eff up it’s ordering. It is not a LinkedList, where you would just swap pointers like that.

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

Sidebar

Related Questions

Don't ask me how but I'm in a situation where I have DCPs published
Don't ask why but I have the requirement to draw a border around certain
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know where else to ask, but from one day to the other my
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know why but I can't find a solution to this. I have 3
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't need to do this right now but thinking about the future... What would
don't know better title for this, but here's my code. I have class user

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.