top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How can I declare this type of array in C?

+2 votes

I need to get value from the below table

{  {1,25,{45,6,4},5,8,{10,15},1,4,0,0},    

first index is fixed to 3 and in each index no of elements fixed to 10, but inside of some index no of elements is not fixed ... so how can i get this value. how to declare it .

I did like array_x[3][10][];

but its not working .. please suggest

posted Jan 28, 2017 by Chakri

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In C least indexes are to be given in the definition like

int a[2][]={{1}, {1,2}}; // invalid statement 
int a[][2]={{1}, {1,2}}; // valid statement 

So in your case x[3][10][] is a invalid statement however x[][10][5] is valid.

PS: I hope I understood your problem correctly, in case not please comment and I will love to help.

answer Jan 29, 2017 by Salil Agrawal
hi thanks for your reply, but please help me how can i declare my third index because its not fixed.

for example

{  {1,25,{45,6,4},5,8,{10,15},1,4,0,0},    
in this how can i get the values of arr[1][3][3] /// i mean to get value 800
and also arr[2][8][6]  /// 777 in this case....

for this type of array how should i declare it .. please help
Sorry for late reply,
As I explained in C we dont have a way to define a multi-dimantional array with variable least index. So I am afraid we may need to find out a alternate way to handle this.
I hope this helps...
Thanks for your suggestions
Similar Questions
0 votes

See the following two program

int main()
  int a[][5] = { 1}; 
  printf("%d", sizeof(a)); 

Output: 20

int main()
  int a[2][5] = { 1}; 
  printf("%d", sizeof(a)); 

Output: 40

Can someone explain the logic why there is such difference of the size?

+1 vote

declare only like arr[10] but here arr[10] is 2-D

+3 votes

We can declare the array in the following two ways, I want to know what is the re-commanded way -

0 votes

Which is the best practice for variable declaration within the function ? Or is it vary from one language to other one ?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.