Frequently Asked Questions (FAQs)

Q1. Why can’t we use NULL to terminate the integer or float array?

Answer:

In C, the null by default is equivalent to 0. So if we want to use NULL as an ending point for an integer or float array, we won’t be able to use 0 as a value of the array element. In some specific cases, it may work but in general, it is meaningless to sacrifice one of the most commonly used digit for this purpose.

Q2. Why does C not allow passing an array by value to the function?

Answer:

The array names in C are inherently treated as a pointer to the first element of the array in most contexts including passing as a parameter. So, when we use the array name to pass it as a parameter, the value of the array name is actually copied to the formal parameter of the function (as happens in call by value), but the value that is copied is the address of the first element. So it seems like the arrays are passed as reference.

Related Articles:



Pass Array to Functions in C

In C, the whole array cannot be passed as an argument to a function. However, you can pass a pointer to an array without an index by specifying the array’s name.

Arrays in C are always passed to the function as pointers pointing to the first element of the array.

Similar Reads

Syntax

In C, we have three ways to pass an array as a parameter to the function. In the function definition, use the following syntax:...

Examples of Passing Array to Function in C

Example 1: Checking Size After Passing Array as Parameter...

Predict the Output of the Below C Programs

...

Frequently Asked Questions (FAQs)

...