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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:55:28+00:00 2026-05-23T13:55:28+00:00

I am a bit confused here. This is from a great C book, and

  • 0

I am a bit confused here. This is from a great C book, and maybe I question it too much, but somehow it didn’t make sense. I hope I can tell my confusion.

Let’s say below &a points to the memory address 87 and &b points to the memory address 120;

int a = 3;
int b = 4;
swap(&a, &b);

void swap(int *px, int *py) {
   int temp;
   temp = *px;
   *px = *py;
   *py = temp;
}

OK, here is the question: When we call function swap and pass the parameters to the function are we actually setting “px” to 87 or are we setting “*px” to 87?

Because if we are setting *px to 87 then by definition of the * sign, we are setting the value where the pointer refers to, but not the memory address p holds, which is wrong in this example. On the other hand, if there we are actually setting “p” to 87 then the code in swap makes sense, because then when we use the * sign in the function we will be referring to the value in that address which is “3” here. But then why is the syntax confusing and looks like as if we are setting

*px = 87

?

  • 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-23T13:55:28+00:00Added an answer on May 23, 2026 at 1:55 pm

    * may mean three different things, depending on the context:

    • In a * b, it means multiplication.
    • In int *a, it means “we are now declaring a variable or parameter a, whose type is int * (pointer to int).
    • In *a (assuming that there is no data type to the left of *, so that this is an expression and not a declaration), it means “a is a pointer, and we want to look at the value it points to (also known as dereferencing the pointer”.

    So the parameter to your method is a, not *a; the asterisk is part of the parameter’s type, and a is what you are setting to 87. Writing pointer declarations as int * a or int* a instead of int *a may help making the distinction between declaration and dereferencing clearer.

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

Sidebar

Related Questions

This might be a very basic question, but I am a bit confused about
Bit confused here, I have an on-demand instance but do I get charged even
I've seen various questions here pertaining to saving NSArrays/NSDictionaries, but I'm a bit confused
I am a bit confused with this paticular blog post here... http://bartdesmet.net/blogs/bart/archive/2006/09/13/4417.aspx What is
I'm a bit confused here. I'm copying all the controls from one form to
I am pretty sure this is a stupid question, but here goes anyway. I
I'm a bit confused here. Microsoft as far as I can tell claims that
You guys were very helpful yesterday. I am still a bit confused here though.
I'm a bit confused on setting up the boost test library. Here is my
I'm a bit confused why I can't initialize a getter this way: @synthesize stack

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.