@sharma: dis has been explained to tiwari...ask him...:)
On Fri, Jun 17, 2011 at 3:12 AM, DIPANKAR DUTTA
wrote:
> instead of calling swap(&ps[0],&ps[1]) can u try with swap(ps[0],ps[1]) or
> swap(&ps[0][0],&ps[1][0]) ?
>
> On Fri, Jun 17, 2011 at 5:05 AM, udit sharma wrote:
>
>> #includevoid swap
#include
void swap(char **p,char **q)
{
char *t;
t=*p;
*p=*q;
*q=t;
}
int main(){
char *ps[2]={
"Hello",
"Good Morning",
};
swap( &ps[0] , &ps[1]);
printf("%s \t %s\n",ps[0],ps[1]);
return 0;
}
This one breaks the ice ... as you have to change the contents of the array
wh
The function swap just swaps it's local copy of pointers which does not mean
that it swap array elements. You have to do it explicitly.
On Fri, Jun 17, 2011 at 3:17 AM, udit sharma wrote:
> Ohh Sry... The qus was:
>
>
>> #includevoid swap(char *,char *);int main(){char *ps[2]={
>>>
Ohh Sry... The qus was:
> #includevoid swap(char *,char *);int main(){char *ps[2]={
>> "Hello",
>> "Good Mornning",
>> };swap(ps[0],ps[1]);printf("%s \t %s\n",ps[0],ps[1]);return 0;}
>> void swap(char *p,char *q){char *t;t=p;p=q;q=t;}
>>
>>
>> why the output is:
>>
instead of calling swap(&ps[0],&ps[1]) can u try with swap(ps[0],ps[1]) or
swap(&ps[0][0],&ps[1][0]) ?
On Fri, Jun 17, 2011 at 5:05 AM, udit sharma wrote:
> #includevoid swap(char *,char *);int main(){char *ps[2]={
> "Hello",
> "Good Mornning",
> };swap(&ps[0],&p
#includevoid swap(char *,char *);int main(){char *ps[2]={
"Hello",
"Good Mornning",
};swap(&ps[0],&ps[1]);printf("%s \t %s\n",ps[0],ps[1]);return 0;}
void swap(char *p,char *q){char *t;t=p;p=q;q=t;}
why the output is:
HelloGood Mornning
--
Regar