0

{
int i = 25789;
char *p;
..............
..............
printf("%d",*p); /* (*p) should give in printf*/
}

dont assign p=i ............apart from this how we can typecast this program so that we can get interger value tp pointer p.............please help me this

4
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

What are you trying to achieve by assigning a (char*) an (int), which is illegal by the way
Please be more clear.

0

"printf("%d", p );" should print the adress of variable which p points to which is an integer.

If you dont assign any adress to the pointer then that pointer is bad ptr. You cant expect to get a meaningful value without assigning .

0

"printf("%d", p );" should print the adress of variable which p points to which is an integer.

OP stated

printf("%d",[B]*p[/B]);

which should attempt to print the value at p. Though your post is correct but the OP isn't clear of what he desires. Plus he is double posting...or threading if I must put it.

0

{
int i = 25789;
char *p;
..............
..............
printf("%d",*p); /* (*p) should give in printf*/
}

dont assign p=i ............apart from this how we can typecast this program so that we can get interger value tp pointer p.............please help me this

This might work:

int i = 25789;
char *p = (char *)&i;

printf("%d\n", *(int*)p);
// The above is the same as this:
printf("%d\n", i);

If you want to show the address store in p instead of the integer then use %p, not %d printf("%p\n", p);

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.