Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Error in Program

This is a discussion on Error in Program within the C and C++ forums, part of the Programming Talk category; I tried declaring my structure as below in my C programming language: struct test { int x,y; char exa[x][y]; }test; ...

  1. #1
    ashlee is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    108

    Exclamation Error in Program

    I tried declaring my structure as below in my C programming language:

    struct test {
    int x,y;
    char exa[x][y];
    }test;

    I got error when I tried the above test structure. Why is it so? Can someone correct my program?


  2. #2
    hvg_99 is offline Junior Member Array
    Join Date
    May 2007
    Answers
    9

    Answer to your question : Error in program

    Question :

    struct test {
    int x,y;
    char exa[x][y];
    }test;
    Hi,

    It so happens that you are trying to declare an array of a variant size and so is the error. The size of the array must be a constant number. You can define a constant and then use that name as the size of the array.

    #define MIN 10
    #define MAX 50
    struct test{
    char exa[MIN][MAX];
    }test;

    int x=10;
    int y=20;
    struct test {
    char exa[x][y];
    }test;

    I hope i have cleared your doubt.

    Gayatri


Latest Article

Network Security Risk Assessment and Measurement

Read More...