Hello every one I dont understand why my output is different
here is my code
Code:
#include <stdio.h>
#include <stdlib.h>
struct {
int len ; //cannot initialize to a value directly
char *str;
int a;
} *p;
//size of pointer is always constant = 4
main(){
p = malloc(sizeof(p));
p->len = 0;
printf("%d\t%d",p->len,p->len++);
}
Expected output
0 0
original output
1 0
and when write almost similar code like this one
Code:
#include <stdio.h>
#include <stdlib.h>
struct {
int len ; //cannot initialize to a value directly
char *str;
int a;
} *p;
//size of pointer is always constant = 4
main(){
p = malloc(sizeof(p));
p->len = 0;
printf("%d\t%d",p->len,p->len+1);
}
I get the out put as
0 1
which is expected
can any one clarify my doubt, is it some thing related to precedence of '++' then why does printf print the first argument as 1 and latter as 0