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. |
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 2 of 3.
Shireen Nagdive said:
1 decade ago
According to me, third statement is false because it is not necessary to give values to the array elements at the time of declaration. We can simply do eg. int array[10];Execute other steps and then through scanf or whatever way can give value to the array elements.
Suman Saurabh said:
1 decade ago
But in question it is not mentioned (Turbo C, or gcc) but in gcc it not necessary that SIZE must be macro it also may be a simple variable.
E.g.
int SIZE = 26;
int num[SIZE];
E.g.
int SIZE = 26;
int num[SIZE];
Rathi said:
1 decade ago
@Gopinath.Nan.
num[26] store the 26 elements because it start with 0,1,2......25.
num[26] store the 26 elements because it start with 0,1,2......25.
Sahini said:
1 decade ago
Why the third statement is false?
Dilini said:
1 decade ago
I want to know why the third statement is false?
Jeff McCracken said:
1 decade ago
SIZE could also be defined as such : int SIZE and thus size would be a valid array index and thus the index SIZE would also be allowed. The way the #4 answer is worded seems to imply that it's ONLY allowed if SIZE is a macro.
The_void said:
1 decade ago
"The declaration num[SIZE] is allowed if SIZE is a macro."
#1
num[SIZE] is not a valid declaration. Be coherent in your questions.
int num[SIZE] or "type" num[SIZE] should be...
#2
Declaration depend of how SIZE macro was defined.
#1
num[SIZE] is not a valid declaration. Be coherent in your questions.
int num[SIZE] or "type" num[SIZE] should be...
#2
Declaration depend of how SIZE macro was defined.
Nick said:
1 decade ago
int a;
#define SIZE a
int num[SIZE];
Na-ah... This question needs to state that the MACRO evaluates to a non-negative integer...
#define SIZE a
int num[SIZE];
Na-ah... This question needs to state that the MACRO evaluates to a non-negative integer...
GOPINATH.NAN said:
1 decade ago
num[26] store the 27 elements because it start with 0,1,2......26.
LIKE THAT only, then how is it true?
LIKE THAT only, then how is it true?
Amit said:
1 decade ago
It is necessary to initialize the array at the time of declaration.
I think this is the correct statement. Please evaluate this option
I think this is the correct statement. Please evaluate this option
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers