0

I initialized my array like this: char x[]={'m'};

It worked. But for the following lines i got error:Size of the type is unknown or zero

char x[][]={{'m'},{'m'}}; 

or

char x[][]={{'m'}};

I am unable to find the reason of the error.

4 Answers 4

1

While defining a 2D array, specifying the column size is mandatory.

char x[][1]={{'m'}};
Sign up to request clarification or add additional context in comments.

Comments

1

You have to set the number of columns. The compiler calculates the number of rows:

char x[][1]={{'m'},{'m'}}; 

Comments

0

For row major architecture, you should specify at least the number of columns. Why? Because, when you assign the values, the compiler has no idea how to assign them in the 2D array.

So, as others have already said, try this:

char x[][1]={{'m'}};

or

char x[1][1]={{'m'}}; // note: specifying the number of rows is redundant

Comments

0

In c you must specify the right most array size, so putting

char x[][1];

would work

3 Comments

thanks..It works..Is there any reason behind specifying right most array size?
Its so that the computer knows roughly how much memory to allocate
@QuinnFTW, That can be figured out from what you initialize it with. What can't be figured out on a general basis is the number of rows and columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.