ऐरे वाले C प्रोग्राम का सही विकल्प चुनें:
Choose the correct option of C program having array:
int main ()
{
int xyz (4) = [10,20,30,40];
printf (“%d”, xyz (1)); }
A
0
B
Compile error
C
10
D
20
Explanation
The given C code is:
int main ()
{
int xyz(4) = [10, 20, 30, 40];
printf("%d", xyz(1));
}
Explanation:
-
Array Declaration: The code attempts to declare an array as
int xyz(4) = [10, 20, 30, 40];.- The correct way to declare an array in C is by using square brackets, not parentheses.
- It should be
int xyz[4] = {10, 20, 30, 40};.
-
Accessing Array: The code tries to access the array using
xyz(1), which is incorrect. The correct way to access the array isxyz[1], notxyz(1).
So, there are syntax errors in both the declaration and the way the array is accessed.
Correct Answer:
(B) Compile error
Correct Answer: B) Compile error