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

Arrays

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

If a is an array of 5 integers then which of the following is the correct way to increase its size to 10 elements?

Question: If a is an array of 5 integers then which of the following is the correct way to increase its size to 10 elements?
[A].

int[] a = new int[5];
int[] a = new int[10];

[B].

int[] a = int[5];
int[] a = int[10];

[C].

int[] a = new int[5];
a.Length = 10 ;

[D].

int[] a = new int[5];
a = new int[10];

Answer: Option D

Explanation:

No answer description available for this question.

If a is an array of 5 integers then which of the following is the correct way to increase its size to 10 elements? Read More »

Arrays, C Sharp 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 is correct about the array declaration given below?

Question: Which of the following statements is correct about the array declaration given below?

[A].

intMyArr refers to a 2-D jagged array containing 2 rows.

[B].

intMyArr refers to a 2-D jagged array containing 3 rows.

[C].

intMyArr refers to a 3-D jagged array containing 2 2-D jagged arrays.

[D].

intMyArr refers to a 3-D jagged array containing three 2-D jagged arrays.

Answer: Option C

Explanation:

No answer description available for this question.

Which of the following statements is correct about the array declaration given below? Read More »

Arrays, C Sharp 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