541 views
0 votes
0 votes
#include<stdio.h>

void swap (char *x, char *y)

{

    char *t = x;

    x = y;

    y = t;

}

int main()

{

  char *x = "raghav";

  char *y = "ravi";

  char *t;

  swap(x, y);

  printf("(%s, %s)", x, y);

  t = x;

  x = y;

  y = t;

  printf("\n(%s, %s)", x, y);

  return 0;

}

1 Answer

0 votes
0 votes
ravi raghav  ::since called swap function with reference

raghav ravi  ::further executionagain swaps the pointer to strings . that why

Related questions

0 votes
0 votes
1 answer
1
Desert_Warrior asked May 16, 2016
775 views
#include<stdio.h int main() { int a[10][20][30] = {0}; int *b = a; int *c = a+1; printf("%ld", c-b); return 0; }
2 votes
2 votes
0 answers
3
0 votes
0 votes
1 answer
4
shekhar chauhan asked Jun 4, 2016
449 views
#include <stdio.h void fc(float *); int main() { int i = 10, *p = &i; fc(&i); } void fc(float *p) { printf("%f\n", *p); }