Re: Pointers in C
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Wed, 21 Feb 2007 11:21:01 +0000
Praveen said:
Hi,
I came across a program as follows
main()
{
int x, y ;
int *p1 = &x;
int *p2 = &y;
printf("%d\n", p1-p2);
}
The output of the above program is 1.
Can some one explain me how it is 1.
Even if the pointer arithmetic were legal (which others have already
pointed out, so I won't belabour it here), the call to printf is not.
Whether the (undefined) result of your illegal pointer arithmetic is
reported correctly by printf is undefined, because you failed to
provide a valid function prototype within the current scope at the
point of call to a variable argument function.
Headers are not decorative. They matter. In future, if you call printf,
do this:
#include <stdio.h>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: Pointers in C
- From: Keith Thompson
- Re: Pointers in C
- References:
- Pointers in C
- From: Praveen
- Pointers in C
- Prev by Date: Re: What is the use of Function Pointers in C language?
- Next by Date: Re: Static Variables
- Previous by thread: Re: Pointers in C
- Next by thread: Re: Pointers in C
- Index(es):
Relevant Pages
|