Thread: Where do I put my curly brackets for array

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    17

    Where do I put my curly brackets for array

    How do you put curly brackets for N dimensional array?

    I don't understand how to put my curly brackets for my array


    Code:
     #include<stdio.h>
    
    int main()
    {
        int i = 0;
    	
    	int array[ 3, 2, 4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }
       
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Code:
    #include <stdio.h>
    
    
    int main()
    {
        int i = 0;
        
        int array[3][2][4] = {
                {{ 1,  2,  3,  4}, { 5,  6,  7,  8}}, 
                {{ 9, 10, 11, 12}, {13, 14, 15, 16}}, 
                {{17, 18, 19, 20}, {21, 22, 23, 24}} 
             };
       
        return 0;
    }
    Note that the definition for the array has changed - those commas shouldn't be in there!

    I'm pretty sure that technically you don't need them, but should, and will get a warning without them:

    Code:
    a.c: In function ‘main’:
    a.c:8:26: warning: missing braces around initializer [-Wmissing-braces]
        8 |     int array[3][2][4] = {
          |                          ^
        9 |              1,  2,  3,  4,  5,  6,  7,  8,
          |              {{           }  {            }}
       10 |              9, 10, 11, 12, 13, 14, 15, 16,
          |              {{           } {             }}
       11 |             17, 18, 19, 20, 21, 22, 23, 24
          |             {{            } {
       12 |          };
          |          }}
    Last edited by hamster_nz; 08-18-2022 at 10:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Curly brackets in a function call? What's that all about :)
    By shrink_tubing in forum C++ Programming
    Replies: 7
    Last Post: 05-30-2022, 02:22 PM
  2. Replies: 3
    Last Post: 09-22-2016, 09:08 AM
  3. Replies: 1
    Last Post: 03-20-2016, 08:58 PM
  4. IF Statement-- With curly brackets or semicolon
    By erdemtuna in forum C Programming
    Replies: 6
    Last Post: 01-10-2016, 06:40 AM
  5. Getting rid of array index brackets
    By jtullo in forum C Programming
    Replies: 3
    Last Post: 04-22-2007, 12:16 AM

Tags for this Thread