Search
 
SCRIPT & CODE EXAMPLE
 

C

variable swap in c

// swap variables in C
void swap(int *x, int *y){
	int temp = *x;
    *x = *y;
    *y = temp;
}
swap(&a, &b); // address of a and b
Comment

swapping two numbers in c

//Author: Subodh
        //! Swap two number using XOR operation
        cout << "Before, n1 = " << num1 << ", n2 = " << num2 << endl;
        num1 = num1 ^ num2, num2 = num1 ^ num2, num1 = num1 ^ num2;
        cout << "After, n1 = " << num1 << ", n2 = " << num2 << endl;
Comment

swap using pointer in c

// swap the value of varible using pointer
#include <stdio.h>
void swap(int *, int *);
int main()
{
    int a = 11;
    int b = 5;
    int *p, *q;
    p = &a; // p holds the address of a
    q = &b; // q holds the address of b
    printf("Before swapping value of a = %d , b = %d 
", *p, *q);
    swap(p, q); // you can use - swap(&a,&b);
    printf("After swapping value of a = %d ,b = %d
", *p, *q);
    return 0;
}
// function that swaps the value of the integer variable
void swap(int *p, int *q)
{
    int t;
    t = *p;
    *p = *q;
    *q = t;
}
Comment

C Programming to swap two variables

#include <stdio.h>

int main()
{
    int x = 20, y = 30, temp;
    temp = x;
    x = y;
    y = temp;
    printf("X = %d and Y = %d", x, y);
    
    return 0;
}
Comment

variable swap in c

// swap variables in C
void swap(int *x, int *y){
	int temp = *x;
    *x = *y;
    *y = temp;
}
swap(&a, &b); // address of a and b
Comment

how to swap values in variables in c

#include <stdio.h>
#include <stdlib.h>

int main()
{
  	//initialize variables
	int num1 = 10;
	int num2 = 9;
  	int tmp;
  	
  	//create the variables needed to store the address of the variables
  	//that we want to swap values
  	int *p_num1 = &num1;
  	int *p_num2 = &num2;
  
  	//print what the values are before the swap
  	printf("num1: %i
", num1);
    printf("num2: %i
", num2);
  
  	//store one of the variables in tmp so we can access it later
  	//gives the value we stored in another variable the new value
  	//give the other variable the value of tmp
  	tmp = num1;
  	*p_num1 = num2;
  	*p_num2 = tmp;

  	//print the values after swap has occured
   	printf("num1: %i
", num1);
    printf("num2: %i
", num2);
  	
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: c program for swapping of two numbers 
C :: passing file as argument in c 
C :: print an int c 
C :: convert char number to int in c 
C :: terraform fargate cpu 
C :: c program to implement mv command 
C :: c language 
C :: powershell search big files 
C :: C fscanf ignore commas 
C :: wifi access point in esp8266 
C :: c list 
C :: rust set toolchain 
C :: Compile multiple C files 
C :: round c 
C :: writing structures in c 
C :: declare an array 
C :: c read file from command line 
C :: bcd to char c 
C :: solutionadda 
C :: how to do Employing defensive code in the UI to ensure that the current frame is the most top level window 
C :: google business customer care number india 24/7 
C :: phpunit assert continue 
C :: can we update values of a map via traversing 
C :: curl ftp upload file to directory 
C :: Clearing The Input Buffer In C/C++ 
C :: google sheets transpose new line to table 
C :: This C Program is used to find the greatest among ten numbers. 
C :: convert curl to http request with authorization header 
C :: how to make play a song javascript 
C :: gsl matrix invert 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =