TL;DR You cannot because the requirement is invalid from C point of view. Array sizes are fixed and cannot grow or shrink whatever be the usage requirement.

Quoting C11, chapter §6.7.6.2, Array declarators (emphasis mine)

In addition to optional type qualifiers and the keyword static, the [ and ] may delimit an expression or *. If they delimit an expression (which specifies the size of an array), the expression shall have an integer type. If the expression is a constant expression, it shall have a value greater than zero. [...]

Also, as per the Initialization syntax, C11, chapter §6.7.9, the brace closed initializer list should have at minimum one initializer element (object). An initializer in form of { }; is invalid C.


Note:

If you meant "How do I make the contents of an array empty in C?", well, in that case, assuming "empty" translates to a value of 0, we can use memset() or a loop-and-assignment to get that done. This, however, makes the array contents empty, not the size of the array.

Answer from Sourav Ghosh on Stack Overflow
Top answer
1 of 4
5

TL;DR You cannot because the requirement is invalid from C point of view. Array sizes are fixed and cannot grow or shrink whatever be the usage requirement.

Quoting C11, chapter §6.7.6.2, Array declarators (emphasis mine)

In addition to optional type qualifiers and the keyword static, the [ and ] may delimit an expression or *. If they delimit an expression (which specifies the size of an array), the expression shall have an integer type. If the expression is a constant expression, it shall have a value greater than zero. [...]

Also, as per the Initialization syntax, C11, chapter §6.7.9, the brace closed initializer list should have at minimum one initializer element (object). An initializer in form of { }; is invalid C.


Note:

If you meant "How do I make the contents of an array empty in C?", well, in that case, assuming "empty" translates to a value of 0, we can use memset() or a loop-and-assignment to get that done. This, however, makes the array contents empty, not the size of the array.

2 of 4
3

Try executing these two cases, so that you can understand what's actually going on with gcc.

CASE 1:

#include<stdio.h>
int main()
{
 int arr[]={};
 printf("size:%d\n",sizeof(arr));
}

CASE 2:

#include<stdio.h>
int main()
{
 int arr[]={};
 arr[0]=100;
 printf("size:%d\n%d\n",sizeof(arr),arr[0]);
}

This is because name of an array represents the address of base element. Also, if you declare an array with particular size, you cannot define the boundaries and you can access memory even out of boundaries till the segment in which the array is declared exhausts out of memory.

Coming to your code factors[] = {};, you cannot do this because this is not declaration of the array factors, though you are trying to assign no values using the {} construct. You can leave the [] empty only when you are initializing the array.

🌐
Medium
medium.com › @martinstm › c-shorts-the-best-way-to-create-empty-collections-6fd00bcec1f3
C# Shorts: The best way to create empty collections | by Tiago Martins | Medium
February 19, 2025 - Returns a cached, singleton empty array (T[]), which avoids allocating new memory each time. Efficient and widely used in .NET libraries. IEnumerable<string> emptyEnumerable = Enumerable.Empty<string>(); Generates an empty sequence (IEnumerable<T>) ...
Discussions

Best way to create an empty collection (array and list) in C# (.NET)
new List() is faster because it just uses a static array in the constructor. new List(0) does the same thing for the 0 case but it also checks whether the argument is out of range first, and also checks whether it's 0 to get to that case. https://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs More on reddit.com
🌐 r/csharp
35
69
August 4, 2020
Is there an "Empty List" singleton in C#? - Stack Overflow
Now, while the above is perfectly ... the array object I just don't care -- I was wondering: Is there "empty immutable IEnumerable/IList" singleton in C#/.NET? (And, even if not, is there a "better" way to handle the case described above?) Java has Collections.EMPTY_LIST immutable ... More on stackoverflow.com
🌐 stackoverflow.com
Any good reason to allow for empty linked list?
Suppose the bank has a list of debts that you have to pay. It’s a linked list. What happens when you pay the last debt? What kind of list do you have now? I would think that you have an empty list… otherwise you will owe money to the bank forever. More on reddit.com
🌐 r/C_Programming
82
6
November 24, 2023
empty array in C and returning a pointer - Stack Overflow
Is this the correct way of making an empty array list? More on stackoverflow.com
🌐 stackoverflow.com
July 14, 2015
🌐
Wordpress
ianvink.wordpress.com › 2022 › 08 › 01 › c-how-to-return-an-empty-list-the-right-way
C#: How to return an empty list the right way (And save #Azure $) | Asp.Net Core, Angular, Xamarin and Maui
August 1, 2022 - They all work, but some fill the Heap and then need to be garbage collected, and others don't. Here's a common way to return a list of Cats. return new List (); Works perfectly well, however, the Heap will be…
🌐
Medium
sheldonrcohen.medium.com › avoiding-null-the-case-for-returning-empty-lists-or-arrays-in-c-6b51648ea5ca
Avoiding null: The Case for Returning Empty Lists or Arrays in C# | by Sheldon Cohen | Medium
September 2, 2024 - Returning empty lists or arrays instead of null can help you write code that’s safer and easier to understand. It eliminates the risk of NullReferenceException when the returned value is used and makes it clear that the method didn’t find anything to return.
🌐
Reddit
reddit.com › r/csharp › best way to create an empty collection (array and list) in c# (.net)
r/csharp on Reddit: Best way to create an empty collection (array and list) in C# (.NET)
August 4, 2020 - Especially since performance of empty collection constructors only matters when building collections procedurally. We should be encouraging people to use immutable data structures instead. ... Hmm, F# developers would like to have a word with you about that. Immutable lists are native to functional programming and they work great (where used appropriately, of course).
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 81033-empty-array.html
Empty Array
July 16, 2006 - You don't have to have it empty. Just fill it up and keep track of your last entry (assuming you aren't using the entire thing). There is no "empty" state in C. You could specify a value as "empty" and check that spot to see if it equals "empty", but there is no such thing as an empty array.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-empty-a-char-array-in-c
How to Empty a Char Array in C? - GeeksforGeeks
July 23, 2025 - We can empty a char array in C by setting all of the elements to ‘\0’. So, we can change every index element to '\0', as the first element is '\0' so the char array[] will be treated as empty.
🌐
Reddit
reddit.com › r/c_programming › any good reason to allow for empty linked list?
r/C_Programming on Reddit: Any good reason to allow for empty linked list?
November 24, 2023 -

Hello, I've been making a linked list, and talking about it with my dad too, he insists that you should be allowed to make an empty linked list, but I don't think there should be, since there's "no reason to store nothing."

Thoughts?

Edit: feel free to continue posting your thoughts, but after some thought, I'll reconsider allowing an empty list, since having the end user work around this issue would probably make it overall more work. Thank you very much for your input though! I'll let my dad know most of you agree with him 😂

Edit 2: alrighty, I've thought about it, I'll definitely be implementing the support for an empty linked list (though I'll have to rewrite a large chunk of code, rip lol) I definitely enjoyed talking with you guys, and I look forward to finally posting my implementation.

Top answer
1 of 18
52
Suppose the bank has a list of debts that you have to pay. It’s a linked list. What happens when you pay the last debt? What kind of list do you have now? I would think that you have an empty list… otherwise you will owe money to the bank forever.
2 of 18
32
There's no reason to store nothing, but my gosh there absolutely are reasons to represent nothing. This thread is full of them. So the question, then, is how do you want to represent an empty list in your code? How do you signal to the program that sometimes there is a list here, and right now, it's empty? You seem to currently want to represent this empty condition external to the list, by creating and freeing the list on-demand. But consider: now every bit of code you have that has to add something to the list has to first check if there even is a list, and create one if there isn't. And every bit of code that removes something from the list has to check if it's the last element, and free the list if it is. People here are suggesting instead to move your representation of an empty list inside the list. Whatever function or bit of code you hopefully re-use to add or remove items from the list can handle this emptiness internally, so any code that uses your list can ignore this fiddly detail. Which one will be a nicer interface will depend on your code, but there's a reason everybody here is suggesting the second one. In almost all situations it makes reading and writing code easier and less error prone.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-check-if-empty-array-in-c
How to Check if Empty Array in C? - GeeksforGeeks
July 23, 2025 - So, it can't use any of them to make the array have a particular size. As a result, the array hasn't got any space to contain elements, which is why the above output shows that the size of the array is 0 bytes. Method 2: As the size of the array is already 0 so no memory is allocated to it. So, it is also empty
🌐
Code Maze
code-maze.com › home › c# empty array: declare, create and initialize
C# Empty Array: Declare, Create and Initialize - Code Maze
1 month ago - Five ways to declare an empty array in C#, measured on .NET 10: which ones allocate, which return the same shared instance, and which to use.
🌐
Cplusplus
cplusplus.com › reference › list › list › empty
std::list::empty
Returns whether the list container is empty (i.e. whether its size is 0). This function does not modify the container in any way.
🌐
Cplusplus
cplusplus.com › reference › array › array › empty
std::array::empty
Returns a bool value indicating whether the array container is empty, i.e. whether its size is 0. This function does not modify the content of the array in any way.
🌐
Stack Overflow
stackoverflow.com › questions › 31394213 › empty-array-in-c-and-returning-a-pointer
empty array in C and returning a pointer - Stack Overflow
July 14, 2015 - Post the definition of list. ... Standard warning: do not cast void * as returned by malloc & friends. too honest for this site – too honest for this site · 2015-07-13 22:07:40 +00:00 Commented Jul 13, 2015 at 22:07 ... Since you do not return p_array, you leak memory.
Top answer
1 of 3
1

In C, linked lists are usually implemented as a series of nodes stored on the heap that point to eachother. The heap is a persistent memory area that runs throughout the life-cycle of the program.

When you create a variable normally in a C function, and the function returns, the variable that you created is no longer accessible. However when you create something on the heap in a function, and the function is returned, the data you allocated on the heap is still there. However, you have no way of accessing it-- unless the function returns a pointer.

So what you would do for create_q() would be to create the linked list on the heap (using a function in stdlib.h called "malloc"), and then you would return a pointer to your first node, letting the main function know where on the heap to find the first node. Then that first node would have a pointer in it, telling the program where on the heap to find the second node, and so forth.

However, you're probably approaching linked lists the wrong way. Unless this is for some sort of homework project, you probably wouldn't want to create an empty linked list. One of the benefits of a linked list is that it's a dynamic structure in which you can easily insert new nodes. You could still have some variable keeping track of the maximum size you want the list to be, but you probably wouldn't want to actually create the nodes until you had to.

Just keep in mind what a linked list is. It's a set of nodes floating on the heap (in C) that each store some data, and contain a pointer to the next node floating on the heap. All you need, to access the linked list, is a pointer to the first node. To add a new node, you simply "walk" through the list till you reach the last node, and then create a new node and have the old-last node point to it.

2 of 3
0
Is this what you had in mind?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct node_t
{
    int value;
    int priority;

    struct node_t *next;
};

static int current_size;
static int max_size;
static struct node_t* head = NULL;

struct node_t* create_q(int);

struct node_t* create_q(int max_terms)
{
    int i; // loop counter/index

    current_size = max_terms;
    max_size = max_terms;

    if( NULL == (head = malloc(sizeof(struct node_t)*max_terms)))
    { // then, malloc failed
        perror("malloc failed for struct node_t list");
        exit( EXIT_FAILURE );
    }

    // implied else, malloc successful

    // set all fields to '0,0,Null'
    memset( head, 0x00, sizeof(struct node_t)*max_terms);

    // set all next links, except last link
    for(i=0;i<(max_terms-1);i++)
    {
        head[i].next = &head[i+1];
    }

    // set last link
    head[i].next = NULL;

    return( head );
} // end function: create_q
🌐
Maixiangyuan
maixiangyuan.ca › post › how-to-check-if-a-list-is-empty-c
how to check if a list is empty c
January 18, 2025 - Determining whether a list is empty in C requires different approaches depending on whether you're using an array or a linked list. Using a size variable for arrays and checking the head pointer for linked lists provides the most reliable and efficient methods.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-empty-a-chash-list
How to empty a C# list?
The Clear() method is the most efficient way to empty a list as it removes all elements in a single operation.