C Practice Test on Arrays

This “C Practice Test on Arrays” providing set of technical and objective type questions on Arrays to test your programming skills.


1. What is the output of following C program?
#include <stdio.h>
int main()
{
int a[3] = {10, 20, 30};
int *p = a + 2;
printf(“%d\n”, p[-2]);
return 0;
}

 
 
 
 

2. What is the output of following C program?
#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i] = i++ + 2;
for(i=0; i<5; i++)
printf(“%d\t”, arr[i]);
return 0;
}

 
 
 
 

3. The elements in the array of the following code are int array[5] = {5};

 
 
 
 

4. What array variable holds?

 
 
 
 

5. What is the output of following C program?
#include<stdio.h>
int main()
{
int a = 0, b = 1, c = 2;
int array[3] = {a, b, c};
printf(“%d \n”, array[1]);
return 0 ;
}

 
 
 
 

6. What is the output of following C program?
#include<stdio.h>
void main()
{
int k=1, n[5], i, sum=0;
for(i=0 ; i<5 ; i++ )
{
sum = i + ++k;
n[i] = sum + ++k;
}
printf(“%d\n”,n[4]);
}

 
 
 
 

7. Passing array as an argument to a function means?

 
 
 
 

8. Which of the following declaration is illegal?

 
 
 
 

9. What is the output of following C program?
#include<stdio.h>
main ()
{
int k=1 , sum=0, i;
for ( i = 0; i < 4 ; i++ )
{
k = i + ++k;
sum = sum+k ;
}
printf(“%d\n”,sum);
}

 
 
 
 

10. What is the output of following code?
#include<stdio.h>
void main ()
{
int x[5] = {9, 4, 7 , 6, 4};
int i, sum=0;
for(i=0 ; i<5 ; i++)
{
x[i] = x[i]+i;
}
for(i=1 ; i<4 ; i++)
{
sum += x[i];
}
printf(“Sum : %d\n”, sum);
}

 
 
 
 

Question 1 of 10

Share this