Can we define Array and Macros

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi,

Q1) Can we define Array? How to define array?
Q2) How the Macros work in C? Do you got any sample?

eg.
Code:
#define MYCASE(_item,_id) \
   case _id: \
     _item##_##_id=_id;\
   break 

  switch(x) {
      MYCASE(widget,23);
  }

How can we make more selection for our #define MYCASE?
Is it posible we add another MYCASE(widget,24);

Thank You.
 

Q1) Can we define Array? How to define array?
Code:
int X[10]; // array of 10 integer numbers
double array_of_doubles[100];
small int two[10][10]; // array 10*10 elements of "small int" type
Q2) How the Macros work in C? Do you got any sample?
a) when you use macros name, C-precompiler pastes in this place macros content. You can use in macros some specific operators (such as ## - concatenate two strings)
b) simple macros
Code:
#define MAX_NUM 10
int array[MAX_NUM];
so we get array with 10 elements...
Code:
#define MYCASE(_item,_id) \ 
   case _id: \ 
     _item##_##_id=_id;\ 
   break 

  switch(x) { 
      MYCASE(widget,23); 
  }
it is equal to this code without macros:
Code:
switch(x)
{
   case 23: widget_23=23; break;
}

Is it posible we add another MYCASE(widget,24);
it is possible...
 

Hi,

Q1) Can we define the array as..
Code:
#define A array[2]={3,5}
If can how the thing work? How the A can know the array elements 3 or 5?

Thank You
 

q1- A can not know 3 and 5 we define it but you may leave a blank instead of writing 2 cuz the array contains 2 elements
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…