What will be the output of below code fragment:
int main() {
int a[];
a[4] = {1,2,3,4};
printf("%d", a[1]);
}
Only one Option is correct. Choose the same. Please note there is Negative Marking for wrong answers.
Garbage Value
O 2
0 Compiler Error
04
Answers
Answered by
0
Answer:
i don't no and sorry
Explanation:
Write a program in HTML for the following output: (i) Arts A. History B. Geography. (ii) Science I. Computer Science II. Physics. (iii) Commerce O English O ...
Answered by
0
Correct question:
What will be the output of the below code fragment:
int main() {
int a[4] = {1, 2, 3, 4};
printf("%d", a[1]);
}
Options:
a) Garbage value
b) 2
c) Compile error
d) 4
Answer:
The output will be b)2.
Explanation:
- The given code fragment starts by declaring an array in the main function.
- The array declared consists of 5 elements having index numbers as 0, 1, 2, 3, and 4.
- The array elements are initialized as follows: a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4, and a[4] = 0 since no values is specified for the fifth element.
- The next line is a print statement.
- It means that the value of second array element, i.e. a[1] is to be printed.
- The value of a[1], i.e., 2 is printed as the output.
Therefore, the output of the given code fragment is 2.
#SPJ3
Similar questions