write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C
#include <stdio.h> int main() { int n1 = 3, n2 = 9, n3 = 2, n4 = 4, n5 = 1; // arr here is an array of pointers int *a[5] = {&n1, &n2, &n3, &n4, &n5}; // printing the array backwards int i = 0, size = 5; for (i = size - 1; i >= 0; --i) { printf("%d ", *a[i]); } printf("\n"); return 0; }
#include <stdio.h> int main() { int a[] = {3, 9, 2, 4, 1}, size = 5; // printing the array backwards int *p = a + size - 1; while (p >= a) { printf("%d ", *p); p--; } printf("\n"); return 0; }
Get Answers For Free
Most questions answered within 1 hours.