Like all online tests, they always seem to get something wrong, and this one is no exception.
Q12
Which of the following is an advantage of using macros over functions?
A12
Values passed to functions must be of a specific data type; values passed to macros do not.
This is completely wrong.
Consider
Code:
#include <stdio.h>
// a totally unchecked macro
#define LESS(a,b) a<b?a:b
// a type checked function
int less ( int a, int b ) {
return a < b ? a : b;
}
int main ( ) {
int a = 2, b = 4;
int c, d;
char *s, *t;
// these work as expected
c = less(a,b);
d = LESS(a,b);
printf( "%d %d\n", c, d );
// this will fail to compile, or at the
// very least draw lots of warnings.
s = less ( "hello", "world" );
// this will compile, may even produce the "expected" answer
// but will randomly fail to give the right answer for less than obvious reasons
t = LESS ( "hello", "world" );
printf( "%s %s\n", s, t );
return 0;
}
I don't regard the ability to silently introduce obscure and hard to find bugs into a program as an advantage.