## Monday, 18 December 2017

1) An array is also known as ___________

a) Subscripted variable
b) Collective array
c) Ordinary variable
d) Similar Quantities variable

2) Till the array elements are not given any specific value, they are supposed to contain all ____________

a) Zero
b) Garbage value
c) One
d) Combination of zero and one.

3) If array is initialized where it is declared, then mentioning __________ of array is optional.

a) Data type
b) Dimension
c) name
d) Data type and Dimension

4) What happen if we assign a value to an array element whose subscript exceeds the size of array.

a) The program will give error
b) No output
c) program will crash
d) none of these

5) What will be output of the following program

int main()
{
int b[4]={5,1,32,4};

int k,l,m;

k=++b[1];

l=b[1]++;

m=b[k++];

printf("%d, %d, %d",k,l,m);

return 0;
}

a) 2, 2, 4
b) 3, 2, 32
c) 3, 2, 4
d) 2, 3, 32

Ans--> Here, ++b[1] means that firstly b[1] will be incremented so, b[1]=2 then assigned to k i.e. k=2.

b[1]++ means firstly b[1] will be assigned to variable l i.e. l=2, Then value stored in b[1] will be incremented i.e. b[1]=3.

b[k++] means first b[k] will be assigned to m i.e. m=32, then value of k will be incremented i.e. k=3.

6) What will be output of the following program where c=65474 and int=2 bytes.

int main()
{
int c[3][4]={2,3,1,6,4,1,6,2,2,7,1,10};

printf("%u, %u\n", c+1, &c+1);

return 0;
}

a) 65482, 65498
b) 65476, 65476
c) 65476, 65498
d) No output

Ans--> Here c[3][4]= {
{2,3,1,6};
{4,1,6,2};
{2,7,1,10}
};

c+1 means c is base address i.e. address of 1st one Dimensional array and on incrementing it by 1 means it points to 2nd one 2 Dimensional array.
So, c+1=65474 + ( 4 * 2)= 65482
But, when we are writing &c, that means address of this whole array i.e.  address of next new array.
So, &c+1=65474 + (12 * 2)=65498

7) what will be output of the following program

int main()
{
int a[5],i=0;

while(i<5)

a[i]=++i;

for(i=0;i<5;i++)

printf("%d,",a[i]);
}

a) garbage value,1,2,3,4
b) 1,2,3,4,5
c) Error
d) Program crash

Ans--> firstly right side of any expression is evaluated, then the left side is evaluated. So, here ++i will be evaluated at first, then a[i].
Hence, when i=0, a[1]=1, then i=1, a[2]=2,...a[4]=4
and a[0]=garbage value

8) What will be output of the following program

int main()
{
float a[]={12.4, 2.3, 4.5, 6.7};

printf("%d, %d", sizeof(a), sizeof(a[0]));

return 0;
}

a) 16 bytes, 4 bytes
b) 4 bytes, 4 bytes
c) 8 bytes, 4 bytes
d) None of these

Ans-->sizeof(a)=number of element * size of each element
=4 * 4 bytes
=16 bytes
sizeof(a[0])=size of 1st element of array a
= 4 bytes

9) Which one of this is equivalent to

int fun(int arr[])

a) int fun(arr)
b) int fun(int s[])
c) int fun(int arr[2])
d) None of these

Ans-->int fun(int arr[]) and int fun(int arr[0]) are equivalent. Both are prototype for function fun(), that accepts one integer array as parameter and return an integer value.

10) In 2 Dimensional Array, it is necessary to mention  _______ dimension.

a) second
b) first
c) both
d) none of these

Ans-->In 2D array, it is necessary to mention the second dimension, whereas the first dimension is optional.

int arr[][3]={12,34,33,45,56,73};

11) An array can be passed to a function by __________

a) Call by reference
b) call by value
c) Call by reference by passing base address to a function
d) Both a and c

12) What will be output of the following program

int main()
{
int arr[4]={3,4,5,6};

int k[4];

k=arr;
printf("%d\n",k[1]);
}

a) Compile Time Error
b) 4
c) No output
d) Program crashes

Ans-->We cannot assign one array to another directly. We can do assignment operation element by element. Thus reports compile time error.