1,653 views

1 Answer

0 votes
0 votes

As a practical matter, there is little difference. They are equally usable as constants in your programs. Some may prefer one or the other for stylistic reasons, but I can't think of any technical reason to prefer one over the other.

One difference is that macros allow you to control the integral type of related constants. But an enum will use an int.

#define X 100L
enum { Y = 100L };

printf("%ld\n", X);
printf("%d\n", Y); /* Y has int type */

Related questions

2 votes
2 votes
1 answer
1
3 votes
3 votes
2 answers
2
sunil sarode asked Nov 4, 2017
2,132 views
Choose the False statements:(a) The scope of a macro definition need not be the entire program(b) The scope of a macro definition extends from the point of definition to ...
0 votes
0 votes
2 answers
3
akankshadewangan24 asked Apr 14, 2017
729 views
#include <stdio.h #define foo(a,b) #b int main(void) { int a=10,b=15,ab=20; // your code goes here printf("%d",ab+foo(a,b)); return 0; } What is the output?
0 votes
0 votes
1 answer
4
Rohan Mundhey asked Oct 7, 2016
465 views
What will be the output of the following program? void main( ) { enum months{July, August, September = 400, October, November = 500, December = 600}; printf("%d, %d, %d, ...