Array in C Programming Exercise I


Ques 1 Array


A collection of items having same data type and store contiguous memory allocation is known as
  a) Array
  b) function
  c) Structure
  d) Union


a is the correct option




Ques 2 Array


Which of the following is advantage of array?
  a) we can only linear access
  b) we can randomelly access
  c) Sequential only Access
  d) All of the above


b is the correct option




Ques 3 Array


What is the output of the given code ?

#include
int main( )
{
    float a=0,b=1,c=2;
    float *array[]={&a,&b,&c};
    b=a=c;
    printf("%d",b);
    return 0;
}

  a) 1.0
  b) 2.0
  c) 3.0
  d) 4.0


b is the correct option




Ques 4 Array


consider the following program:

int f(int *p,int n)
{
    if(n<=1) return 0;
    else return max (f(p+1,n+1),p[0]-p[1]);
}
int main( )
{
    int a[]={3,5,2,6,4};
    printf("%d",f(a,5));
}

Note: max(x,y) returns the maximum of x and y.
The value printed by this program is____________

  a) 2
  b) 3
  c) 4
  d) 5


b is the correct option




Ques 5 Array


Let A be a square matrix of size nxn .consider the following pseudocode .what is the expected output ?

C=100;
for i=1 to n do
    for j = 1 to n do
    {
        Temp=A[i][j]+C
        A[i][j]=A[j][i]
        A[j][i]=Temp-C
}
for i=1 to n do
    for j=1 to n do
        Output(A[i][j]);

  a) The matrix A itself.
  b) Transpose of matrix A
  c) Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A
  d) None of the above


a is the correct option