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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:25:22+00:00 2026-06-07T20:25:22+00:00

void swap(char *a,char *b){ char t; t = *a; *a = *b; *b =

  • 0
void swap(char *a,char *b){
  char t;
  t = *a;
  *a = *b;
  *b = t;
}
int main(void){
  char  a = '1';
  char b = '2';

  swap(&a,&b);
  printf("The value is %c and %c respectively\n",a,b);
  return 0;
}

in the above code, there’s a spot that confuse me

I think if a is a pointer, and *a is the value it points to

int *ptr, a = 1;

ptr = &a;
printf("The value of *ptr should be a: %d\n",*ptr);
printf("The value of *a should be an hex address: %p\n",ptr);

so in the swap(char *a, char *b) function,it takes the value not pointer( *a not a),

swap(&a, &b)
but it actually pass the pointer value to it as the parameter, and the code works. Anybody can explain it to me?(I think for swap(char *a){...} part, the declaration doesn’t mean it require *a to pass in, it means declare a pointer value a, not the value a points to as *ain elsewhere means).

  • 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-07T20:25:23+00:00Added an answer on June 7, 2026 at 8:25 pm

    * is confusing because it means two different, but closely related, things. In a variable declaration, * means “pointer”. In an expression, * means “dereference the pointer”.

    It’s intended to be a helpful mnemonic: if you have char *a in your code it means that *a is a char.

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

Sidebar

Related Questions

I have the following code: #include <stdio.h> void insertion_sort(char[], int); void swap(char*, char*); int
Write a function called swap which has a prototype of void swap (int&, int&);
//fpoin1.c #include<stdio.h> #include<conio.h> #include<fpoin.c> void swap(int,int); void main() { int i=0; i++; if(i<=5) {
#include <stdio.h> void fun(char a[]){ a[0]^=a[1]^=a[0]^=a[1]; } int main(int argc, char **argv){ char b[10];
void swap(int &first, int &second){ int temp = first; first = second; second =
#include stdio.h #include conio.h void swap(int *x,int *y); void main() { int a=10,b=20; swap(a,b);
I am studying pointers and I encountered this program: #include <stdio.h> void swap(int *,int
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
#include <iostream> using namespace std; template < class T > void swap (T& a,
Hi I'm trying to do a simple swap of two objects.My code is void

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.