C Programming - Arrays - Discussion

Discussion Forum : Arrays - Point Out Correct Statements (Q.No. 5)
5.
Which of the following statements are correct about an array?
1: The array int num[26]; can store 26 elements.
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.
4: The declaration num[SIZE] is allowed if SIZE is a macro.
1
1,4
2,3
2,4
Answer: Option
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.

Discussion:
21 comments Page 1 of 3.

Gowtham raj said:   8 years ago
Size is not only a macro it may be a variable also.
(2)

Pranali said:   8 years ago
@Niharika.

Writting macro means we have to replace that particular value/function/whatever with another value(same like find and replace method).

How to write macro?

ans=> # define a 10;
that means the value'10' will replace at the position of ' a' throughout the program.
'#' indicates that it is(macro expansion is) work of preprocessor.

Pranali said:   8 years ago
@Nidhi Goud.

Because an array allocates memory at compile the time not at runtime, so we have to say to the compiler that 'my array will contain 1,2,etc (any one digit) number of elements'. got it?

Pranali said:   8 years ago
@Amit.

It is not compulsory to initialize array at the time of declaration.
we can initialize array member by member also.as,

arr[0]=1;
arr[1]=2;
.
.
.
.etc

Iggi said:   8 years ago
num[SIZE] is not a proper DECLARATION.
DECLARATION would be int num[SIZE];

Niharika said:   9 years ago
What does macro mean? Pease anyone say me.

Kiruba said:   9 years ago
I am totally confused. Someone plese explain.

Nitish said:   9 years ago
Yes, it can store 26 elements, and also 27 elements. Statement does not say it store only 26 elements.
(2)

Nidhi goud said:   10 years ago
Why y is necessary to give the size of an array in an array declaration?

Vijay said:   1 decade ago
Third statement is false because it is not must initialization of array, at the time of declaration.

int num[26];true.
int num[]={0, 1, 2.25};true.

Because sizeof(num) --->52B (2*26).

But int num[];error. Means initialization not must and should at the time of declaration but specify the arr size is must.


Post your comments here:

Your comments will be displayed after verification.