Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using #define in C Program

I am trying to use #define to define a constant in my program. I realize I could use const, but I am trying to get a good understanding of #define. Could someone please explain why the following code does not work, and should be done instead?

#include <stdio.h> #define M 20; typedef int Marray_t[M][M]; //I can't define an M x M array  int main() {   Marray_t A;   int i;    for (i = 0; i < M; ++i) { //Can't iterate up to M     A[i] = i;   }    return 0; } 
like image 379
Oliver Spryn Avatar asked Mar 17 '13 18:03

Oliver Spryn


People also ask

What is the synonym of using?

The words employ and utilize are common synonyms of use. While all three words mean "to put into service especially to attain an end," use implies availing oneself of something as a means or instrument to an end. willing to use any means to achieve her ends.

What does use mean?

Definition of use (Entry 1 of 2) transitive verb. 1 : to put into action or service : avail oneself of : employ. 2 : to expend or consume by putting to use —often used with up.

What is the act of using something?

noun. the act of employing, using, or putting into service: the use of tools. the state of being employed or used. an instance or way of employing or using something: proper use of the tool; the painter's use of color. a way of being employed or used; a purpose for which something is used: He was of temporary use.

What type of word is use?

As detailed above, 'use' can be a noun or a verb. Noun usage: The use of torture has been condemned by the United Nations. Noun usage: There is no use for your invention.


1 Answers

You must remove ; after20, like this

#define M 20 
like image 59
nabroyan Avatar answered Sep 22 '22 06:09

nabroyan