How to use interchange comma operator in c language

Interchange Comma operator

On this page

Comma operators

Program to use interchange Comma operator in c language

#include<stdio.h>
  int main()
  {
    int c = 5,d = 6, temp;
    printf("c = %d, d = %d\n",c ,d);
    temp = c, c = d, d = temp;
    printf("c = %d, d = %d\n",c ,d);
    return 0;
  }
  

Output

c = 5, d = 6
  c = 6, d = 5
  

Steps Description

  • Declare integer three variable c , d and temp
  • initialize in integer variable c = 5 , d = 6
  • printf inbuild function display variable c and d with decimal placeholder %d
  • Assign temp variable with variable c value
  • Assign variable d value with temp variable
  • printf inbuild function display variable c and variable d with decimal placeholder %d