int main
{
int size, j;
scanf("%d", &size);
int arr[size];
for(j=1; j<=size; j++)
{
scanf("%d", arr[j]);
printf("%d", arr[j]);
}
return 0;
}
Example
- The code is erroneous since the values of an array are getting scanned through the loop.
- The code is erroneous since the statement declaring an array is invalid.
- The code is erroneous since the subscript for an array used in for loop is in the range 1 to size.
- The code is correct and runs successfully.
The correct option is (b).
Explanation:
In program the statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required for initialize the size of array. For Example: int arr[20];
Therefore the code is erroneous since the statement declaring an array is invalid.
## 12) Are the expression &arr and arr different for an array of 15 integers?
The correct option is (a).
Explanation:
Yes, both mean two different things. 'arr' gives the address of first int, whereas the '&arr' gives the address of array of ints.
Therefore the expression '&arr' and 'arr' are different for an array of 15 integers.
## 13) Is there any difference in the below declarations?
int fun (int arr[5]);
int fun(int arr);
Example
The correct option is (b).
Explanation:
No, both the declarations are same. It is a prototype for function fun() that accepts one integer array as parameter and an integer value is return.
## 14) What will be the output of the below program?
include<stdio.h>
int main
{
int arr[2]={20};
printf("%d\n", 0[arr]);
return 0;
}
Example
The correct option is (c).
Explanation:
Step 1: int arr[2]={20}; The variable arr[2] is declared as an integer array with size of '3' and it's first element is initialized with value '20'(means arr[0]=20)
Step 2: printf("%d\n", 0[arr]); It prints the first element value of variable 'arr'.
Therefore the output of the program is 20.
## 15) What will be the output of the program if an array begins with address 65486?
include<stdio.h>
int main
{
int arr = {10, 11, 12, 15, 23};
printf("%u, %u\n", arr, &arr);
return 0;
}
Example
- 65486, 65486
- 65486, 65490
- 65486, 65487
- 65486, 65488
The correct option is (a).
Explanation:
Step 1: int arr[] = {10, 11, 12, 15, 23}; The variable 'arr' is declared as an integer array and initialized.
Step 2: printf("%u, %u\n", arr, &arr); Here, the base address of the array is 65486.
Hence the arr, &arr is pointing towards the base address of the array arr.
Hence the output of the program is 65486, 65486