Initializing Array of Pointers

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was looking one question in Stackoverflow here.

Answers are inconclusive it looks and thought expert opinion from this forum.

 

OP asks if array of pointers can be initialized like below even though there are other methods such as ar2[3][4] = {....}.

 

int *ar2[NUM_ROWS]={
                    (int[]){11,12,13,14},
                    (int[]){21,22,23,24},
                    (int[]){31,32,33,34},
                    };

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What a curious coincidence. I made a post today about something completely unrelated:
.
https://www.avrfreaks.net/comment/2496636#comment-2496636
.
However the piece of example C in that just happens to be about 2D arrays and how to initialise them. Might be worth a look.
.
Each entry in the outer dimension array is a pointer to a single dimension inner array.

Last Edited: Tue. Jun 26, 2018 - 06:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you are saying OP's code in SO post is valid?

Also I guess uint16_t (*bar)[COLS] is equivalent to uint16_t *bar[ROWS]. Correct me if I am wrong in this general C concept case.