Reputation: 5541
I have a problem statement, please help me answer this:
Define a macro that receives an array and the number of elements in the array as arguments. Write a program using this macro to print out the elements of an array.
Upvotes: 0
Views: 4473
Reputation: 23
#include<stdio.h>
#define PRINTARRAY(array, length) \
for(int i = 0; i < length; i++) \
printf("%d\t", array[i]);
int main(void) {
int array[5] = {4, 2, 3, 1, 0};
PRINTARRAY(array, 5);
return 0;
}
Upvotes: 1
Reputation: 182664
Here's a start:
#define PRINT(a, n) do { \
int i; \
for (i = 0; ?; ?) { \
? \
} \
} while(0)
Upvotes: 3