-1
void appendToList(int list [], int data) {
    int temp[(sizeof list/sizeof int)+1] = list;
};

It seems to be a problem with the adding one.

I thought that I should be able to create an array with 1 more space than the original but it throws this error.

The second error (line 26) is fatal.

trial.c:27:22: warning: 'sizeof' on array function parameter 'list' will return size of 'int *' [-Wsizeof-array-argument]
   27 |     int temp[(sizeof list/sizeof int)+1] = list;
      |                      ^~~~
trial.c:26:23: note: declared here
   26 | void appendToList(int list [], int data) {
      |                   ~~~~^~~~~~~
trial.c:27:34: error: expected expression before 'int'
   27 |     int temp[(sizeof list/sizeof int)+1] = list;
      |                                  ^~~
  • 1
    You should be compiling with `-std=c17 -pedantic -Wall -Wextra -Werror`. The first message is just as critical as the one listed as error. (That one is actually just a silly syntax error - you can't take `sizeof` on a type like `int` without using parenthesis.) – Lundin Aug 14 '23 at 10:43
  • 1
    ```int list[]``` is the same as passing an array by pointer to it such as ```int* list```. Either you have to provide size like ```int list[100]``` or an extra argument like ```int list[], unsigned int list_size``` – Iman Abdollahzadeh Aug 14 '23 at 10:45

0 Answers0