Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Describe this array statement?

Describe the following array statement:

#define N 60

........

int x[N];

Update:

Now, how can I describe this array statement:

#define A 33

#define B 130

.......

char agenda[A][B];

4 Answers

Relevance
  • ?
    Lv 5
    10 years ago
    Favorite Answer

    define is a preprocessor directivities. When you compile the program, before passing the program through the compiler it passes through several process. Preprocessor directivities is one of them .

    Before passing through the compiler it passes through the prepossesor. directivities.

    # define N 60

    in this statement N is called Macro templates and 60 is called macro exponential. this preprossesor scan your program, it find the variable N. when it found, it replace the value 60 instead of N. and than it passes through the compiler for Binary conversation.

    so in your program int x[N]; is equal-to int x[60];

    For a large program.......suppose you have use the variable hundred times in your program. But after sometime you change the value of a. Then you have to change 100 times. so it is better to use preprocessor directivities. In this case you have to change only one time.

    okkkkkkkkkkkk

    same thing will be happen in the case of A and B. Preprocessor directivities replace the value 33 and 130 instead of A and B.

    Try this Example ....

    #include<stdio.h>

    #define N 10

    #define T 20

    void main()

    {

    int n,i,j;

    char a[N][T];

    for(i=0;i<=9;i++)

    for(j=0;j<=19;j++)

    scanf("%c",&a[i][j]);

    for(i=0;i<=9;i++)

    for(j=0;j<=19;j++)

    printf("%d\n",a[i][j]);

    }

    Source(s): me
  • 10 years ago

    Dear Arjun,

    Its quite a straightforward definition. The statements say that you had defined a constant with the name of N using the #define preprocessor and then when declaring an array you had passed that as its size.

    So the above statement is same as:

    int x[60]; // An array is defined as DATA TYPE NAMEOFARRAY[SIZEOFARRAY];

    The obvious reason for doing the same is that if you have a large program and later on you need to change your size from 60 to 600 or whatever or you want to reduce the size, you only need to make a change once i.e. on top like #define N 300 and now all the arrays containing N as size shall be re-sized accordingly.

  • Anonymous
    10 years ago

    Define creates a compiler variable 'N' with the value 60.

    int x[N]; creates an integer array of size N. Since N is 60 the array is size 60. Therefore his array statement declares and array of 60 integers and allocates the memory needed for an array of 60 integers.

  • Anonymous
    10 years ago

    When you write a statement like this in your program:

    #define N 60

    and execute it, wherever you have used N in your program (except in strings), the token N gets replaced by 60 even before compiling.

    So when you write:

    #define N 60

    ........

    int x[N];

    it becomes:

    int x[60]

    Same thing happens when you are creating 2 dimensional arrays

    The declaration has numbers instead of variables during compiling and running of the code.

Still have questions? Get your answers by asking now.