-
October 29th, 2012, 12:07 AM
#1
Help needed for a pointer program
Hi,
Can anyone explain the below outputs of the program (with malloc statement and without malloc statement).
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *p;
p = (char *) malloc(10);
printf("%d\n", p);
printf("%d\n", *p);
printf("%d\n", sizeof(p));
printf("%d\n", sizeof(*p));
printf("%d\n", sizeof(&p));
return 0;
}
The outputs I got (using gcc 4.5 on linux):
without malloc:
----------------
madhu@Ideapad:~/Desktop$ ./a.out
-1217282060
124
4
1
4
With malloc:
---------------
madhu@Ideapad:~/Desktop$ ./a.out
138657800
0
4
1
4
Thanks in advance!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|