Try asking your compiler.
Code:
#include <stdio.h>
int main(void)
{
int a [] = {5, 15, 34, 54, 14, 2, 52, 72};
int *p = &a[1];
int *q = &a[5];
/* (a) What is the value of *(p+3)? */
printf("*(p+3) = %d\n", *(p+3));
/* (b) What is the value of *(q-3)? */
printf("*(q-3) = %d\n", *(q-3));
/* (c) Can I perform addition and subtraction on pointers? If so, what is q - p? */
printf("q - p = %d\n", (int)(q-p));
/* (d) Is the condition p < q true or false? */
printf("p < q = %s\n", p < q ? "true" : "false");
/* (e) Is the condition *p < *q true or false? */
printf("*p<*q = %s\n", *p<*q ? "true" : "false");
/* (f) Can I do the following, *p = a [4]; ? */
*p = a [4]; /* yup */
/* (g) What happens when I do this, *p = *q; ? */
*p = *q;
printf("*p = %d, *q = %d\n", *p, *q);
/* (h) What happens when I do this, p = q; ? */
p = q;
printf("p = %p, q = %p\n", (void*)p, (void*)q);
/* (i) Is it legal for me to write the following line: p = a; ? */
p = a;
/* (j) Is it legal for me to write the following line: p = a [1]; ?
p = a[1]; // no -- Type mismatch (assignment) (int * = int)
*/
return 0;
}
[edit1]D'oh! Forgot the *p = *q; part (g).[/edit1]
[edit2]Grrrr. *q in printf format literal instead of q (h).[/edit2]