in Programming in C retagged by
1,282 views
0 votes
0 votes
/*strcpy"copy t to s; */

void strcpy(char *s, char *t)

{

while((*s++=*t++) !='\0');

}

 

Can anyone explain how *s++ or *t++ is being executed. As * and ++ are unary operators here , they will have same precedence. Unary operators having same precedence are executed from right to left(right associative). So here if we take *s++ is the increment operator being executed first or the dereferencing operator?. Can anyone show the steps of executing this function.
in Programming in C retagged by
by
1.3k views

3 Comments

hope it helps....

0
0
Really appreciate your effort Akash. One doubt though.

So actually increment is taking place first then the deferencing right?. As it is post increment it actually works the way we want to.  So it would have been completely different had it been a pre increment operator like *++s right?
0
0
dereferencing first and then incrementing

incase of preincrement, increment and then dereference

try executing this simple code to understand the working of pre and post

#include<stdio.h>
int main()
{
    int n=10;
    printf("%d",++n);
    printf("%d",n++);
}
0
0

1 Answer

1 vote
1 vote
the value of *t++ is the character that t pointed to before t was incremented;the postfir ++ doesnt change t untill after this character has been fetched....

referce dennis m ritchie last para...go through that..

Related questions