main()
{

      char s[19];

      strcpy(s,"\0");

      if(s==NULL)
      printf("daniweb\n");
      else
      printf("nitin\n");

      return 0;
}

Can anyone tell me what is expected o/p of this and why ? help! thanks in advance.

I_m_rude
Deleted Member

now, thanks for replying as i waiting for that. now, sir, what will be content of s ? isn't it two null characters ?

and secondly,

int f(int *a)
{
int b=5;
a=&b;
}
main()
{
int i;
printf("\n %d",i);
f(&i);
printf("\n %d",i);
}

what is o/p for this ? i am confused in this a little bit.

Edited 4 Years Ago by I_m_rude

isn't it two null characters ?

No, because strcpy() stops at a null character.

what is o/p for this ?

It's undefined in a big way. Both printf() statements are trying to print an uninitialized variable. f() doesn't do jack diddly to i, as a is a copy of the address of i. You're only modifying the copy, and the original remains unchanged.

will you please again explain your last line in the last post ? f() doesn't do jack diddly.....

but , it is not playing with value of i, rather it is playing with value of a. then why u saying that ?

but , it is not playing with value of i, rather it is playing with value of a.

Correct.

then why u saying that ?

Because changing where a points to has absolutely no effect on i. If you had dereferenced a and copied the value of b into it then you would have indirectly initialized i:

int f(int *a)
{
    int b = 5;
    *a = b;
}

But the f() you posted is completely nonsensical as it only works with the local pointer, does nothing else, and immediately loses all of those changes when the local objects are destroyed upon return.

james sir, tell me one thing, when i am storing address of local variable in a , then after that object destroys, then a will still have its adress na ?

when i am storing address of local variable in a , then after that object destroys, then a will still have its adress na ?

a is a local variable too, it's destroyed at the same time as b. So the answer is no, because a no longer exists.

Edited 4 Years Ago by deceptikon

ohh yes yes! damn good. okies i got it! sir , what is the difference between run time eror and semantic error ?

This article has been dead for over six months. Start a new discussion instead.