Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

C Programming

Is there any difference int the following declarations?int fun(int arr[]);int fun(int arr[2]);

Question: Is there any difference int the following declarations?int fun(int arr[]);int fun(int arr[2]);
[A].

Yes

[B].

No

Answer: Option B

Explanation:

No, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.

Is there any difference int the following declarations?int fun(int arr[]);int fun(int arr[2]); Read More »

Arrays, C Programming

In C, if you pass an array as an argument to a function, what actually gets passed?

Question: In C, if you pass an array as an argument to a function, what actually gets passed?
[A].

Value of elements in array

[B].

First element of the array

[C].

Base address of the array

[D].

Address of the last element of array

Answer: Option C

Explanation:

The statement ‘C’ is correct. When we pass an array as a funtion argument, the base address of the array will be passed.

In C, if you pass an array as an argument to a function, what actually gets passed? Read More »

Arrays, C Programming

Which of the following statements are correct about the program below?

Question: Which of the following statements are correct about the program below?

[A].

The code is erroneous since the subscript for array used in for loop is in the range 1 to size.

[B].

The code is erroneous since the values of array are getting scanned through the loop.

[C].

The code is erroneous since the statement declaring array is invalid.

[D].

The code is correct and runs successfully.

Answer: Option C

Explanation:

The statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required here.

Example: int arr[10];

One more point is there, that is, usually declaration is not allowed after calling any function in a current block of code. In the given program the declaration int arr[10]; is placed after a function call scanf().

Which of the following statements are correct about the program below? Read More »

Arrays, C Programming

Does this mentioning array name gives the base address in all the contexts?

Question: Does this mentioning array name gives the base address in all the contexts?
[A].

Yes

[B].

No

Answer: Option B

Explanation:

No, Mentioning the array name in C or C++ gives the base address in all contexts except one.

Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression.

When you pass an array name as a function argument, you are passing the “value of the pointer”, which means that you are implicitly passing the array by reference, even though all parameters in functions are “call by value”.

Does this mentioning array name gives the base address in all the contexts? Read More »

Arrays, C Programming

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address?

Question: Which of the following statements mentioning the name of the array begins DOES NOT yield the base address?

[A].

A

[B].

A, B

[C].

B

[D].

B, D

Answer: Option B

Explanation:

The statement 1 and 2 does not yield the base address of the array. While the scanf() and printf() yields the base address of the array.

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address? Read More »

Arrays, C Programming

Which of the following statements are correct about 6 used in the program?int num[6];num[6]=21;

Question: Which of the following statements are correct about 6 used in the program?int num[6];num[6]=21;
[A].

In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type.

[B].

In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.

[C].

In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size.

[D].

In both the statement 6 specifies array size.

Answer: Option B

Explanation:

The statement ‘B’ is correct, because int num[6]; specifies the size of array and num[6]=21; designates the particular element(7th element) of the array.

Which of the following statements are correct about 6 used in the program?int num[6];num[6]=21; Read More »

Arrays, C Programming

Which of the following statements are correct about an array?

Question: Which of the following statements are correct about an array?

[A].

1

[B].

1,4

[C].

2,3

[D].

2,4

Answer: Option B

Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.

2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.

3. It is necessary to initialize the array at the time of declaration. This statement is false.

4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.

Hence the statements ‘1’ and ‘4’ are correct statements.

Which of the following statements are correct about an array? Read More »

Arrays, C Programming