Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that a is a one-dimensional array, i is an integer variable, and p is a

ID: 3817167 • Letter: S

Question

Suppose that a is a one-dimensional array, i is an integer variable, and p is a pointer variable that references (points to) an integer. Assuming that the assignment p = a has just been performed, which of the following expressions are illegal because of mis-matched types? Circle your choice(s). (a) p == &a; [0] (b) i == &p; (c) *p == a[0] (d) p == a[0] (e) p[0] == a[0] Show the output from the following legal C program. # include # define N 5 int main(void) { int i, *p; int a[N] = {2, 4, 6, 8, 10}; for (p = a; p = 0; i--) { printf(%d, a[i]); } }

Explanation / Answer

1) a) p = &a[0]; [Its correct and NOT ILLEGAL , we can write p = a or p = &a[0] both means the same]

b) i = &p. [Its Illegal because i is integer and it cant hold address of p]

c) (*p)==a[0][Its correct and NOT ILLEGAL , because we are comparing values at first position of array]
d)
( p)==a[0][Its ILLEGAL , because we are comparing address of p and values at first position of array]

c) p[0]==a[0][Its correct and NOT ILLEGAL , because we are comparing values at first position of array , *p and p[0] means the same thing]

2) Answer is only 11, 8 , 7 , 4 , 3

Explanation : p Starts with first elements and increments it by 1 , ie 2 becomes 3

and then jumps to 2nd position to its right i.e 4 becomes 5

and so on , 6 becomes 7 and 10 becomes 11

And we print the Output in Reverse order so It prints 11, 8 , 7 , 4 , 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote