Suppose that a is a one-dimensional array, i is an integer variable, and p is a
ID: 3817162 • 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 mismatched 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 2 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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.