Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,819 answers

573 users

How to swap two numbers with pointers in C

1 Answer

0 votes
#include <stdio.h> 

void swap(int *n1, int *n2);

int main(void)
{
    int a = 29, b = 85;
    
    swap(&a, &b);
    
    printf("a = %i b = %i", a, b); // a = 85 b = 29
    
    return 0;
}
void swap(int *n1, int *n2)
{
    int tmp = *n1;
    
    *n1 = *n2;
    *n2 = tmp;
}

/* 
run:

a = 85 b = 29

*/




answered Sep 20, 2014 by avibootz

Related questions

1 answer 121 views
2 answers 203 views
1 answer 233 views
2 answers 205 views
3 answers 182 views
182 views asked Jan 14, 2021 by avibootz
2 answers 327 views
...