Rishu said:
hello everybody can anybody tell me about the following programme.
int *ptr;
int a;
ptr=&a;
This isn't a program; the assignment statement isn't inside a
function. So fixing it in the obvious way:
int main(void)
{
int *ptr;
int a;
ptr = &a;
// then ptr++ and (*ptr)++
return 0;
}
then what is the diffrence between ptr++ & (*ptr)++
One increments `ptr`. The other increments whatever `ptr` points
to, in this case `a`, getting undefined behaviour because `a`
is uninitialised.
[If `a` had been declared outside `main`, then it would be
(implicitly) initialised to zero.]
[I choose to write `(*ptr)++` as `*ptr += 1` because I think
it's easier to read and because the result of the increment
isn't used elsehere, but that's just my religion.]
[I'd also start the body of main as
int a;
int *ptr = &a;
because, why defer the initialisation of `ptr`? And probably
I'd initialise `a`, but in this case I don't know what to.]
--
"I just wonder when we're going to have to sit down and re-evaluate /Sahara/
our decision-making paradigm."
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England