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

  • Home
  • SEARCH
  • 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 8674355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:41:26+00:00 2026-06-12T19:41:26+00:00

I’m very confused why this code works. I was taught that a pointer was

  • 0

I’m very confused why this code works. I was taught that a pointer was a “capsule” holding the address of something. So the swapnum function should be expecting one of those “capsules”, not the actual address of the int. Is it creating a temporary pointer and setting it to that address? If that’s the case, then what would be happening if I passed a pointer in by reference such as int * c = &a; swapnum (&c...?

#include <stdio.h>

void swapnum(int *i, int *j) {
  int temp = *i;
  *i = *j;
  *j = temp;
}

int main(void) {
  int a = 10;
  int b = 20;

  swapnum(&a, &b);
  printf("A is %d and B is %d\n", a, b);
  return 0;
}
  • 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-12T19:41:27+00:00Added an answer on June 12, 2026 at 7:41 pm

    pointer is just another word for address. There’s nothing really magic about it, it is just a variable that contains a number, that number being the memory address of the thing it points to.

    In your example, memory might look like this:

    0x00001004 - 10         # a
    0x00001008 - 20         # b
    0x0000100C - 0x0001004  # i
    0x00001010 - 0x0001008  # j
    0x00001014 - 00         # temp
    

    i and j are both int* which means they contain an address that contains an integar. The code *i says “return whatever value is at the address in i and assume it is an int.

    So if you look at your swapnum, here’s what happens:

    int temp = *i;
    # take the value at 0x0001004 (10) and place it in 0x00001014
    
    *i = *j;
    # place the value at 0x0001008 (20) and place it in 0x00001004
    
    *j = temp;
    # place the value at 0x0001014 (10) and place it in 0x0001008
    

    After which memory looks like this:

    0x00001004 - 20         # a
    0x00001008 - 10         # b
    0x0000100C - 0x0001004  # i
    0x00001010 - 0x0001008  # j
    0x00001014 - 10         # temp
    

    You could certainly do this:

    int* c = &a;
    swapnum(c, &b);
    

    All you are doing is getting the address of a, putting it in c and then passing it into swapnum, which expects an address. A pointer is just an address.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text

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.