781 views
0 votes
0 votes

/* function definition to swap the values */
void swap(int *x, int *y) {

   int temp;
   temp = *x;    /* save the value at address x */
   *x = *y;      /* put y into x */
   *y = temp;    /* put temp into y */
 
   return;
}

#include <stdio.h>
 
/* function declaration */
void swap(int *x, int *y);
 
int main () {

   /* local variable definition */
   int a = 100;
   int b = 200;
   int c;
   printf("Before swap, value of a : %d\n", a );
   printf("Before swap, value of b : %d\n", b );
 
   /* calling a function to swap the values.
      * &a indicates pointer to a ie. address of variable a and
      * &b indicates pointer to b ie. address of variable b.
   */
   c=b+5;
   swap(&a, &c);
 
   printf("After swap, value of a : %d\n", a );
   printf("After swap, value of b : %d\n", b );
 
   return 0;
}

/*IF I USE swap(&a,&(b+5)),it gives error but the above program doesn't give error.

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
Adiaspirant asked Jan 1, 2017
258 views
If pointer to leaf node of max heap given, what is the time complexity to find smallest element?
0 votes
0 votes
0 answers
2
Adiaspirant asked Jan 1, 2017
164 views
If pointer to leaf node of binary heap given, what is the time complexity to find smallest element?