Passing values directly as array to function in C [duplicate] Passing values directly as array to function in C [duplicate] arrays arrays

Passing values directly as array to function in C [duplicate]


TL;DR The functions expects a (pointer to) an array as input argument, so you have to pass one. There's no way you can call this without an array.

That said, if you meant to ask "without creating an additional array variable", that is certainly possible. You can achieve that using something called a compound literal. Something like:

 printArr( (int []){3, 4, 5} );

should work fine.

To quote C11, chapter §6.5.2.5

[In C99, chapter §6.5.2.5/p4]

A postfix expression that consists of a parenthesized type name followed by a brace-enclosed list of initializers is a compound literal. It provides an unnamed object whose value is given by the initializer list.

That said, printArr() and printArray() are not same, but I believe that's just a typo in your snippet.