C Technical Interview Questions on Arrays

These C Technical Interview Questions on Arrays post providing basic, intermediate and Hard level examples in C Arrays. The Practice of these examples makes you good in C programming.


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);
}

  1. 14
  2. 30
  3. 24
  4. 20

Answer :

Ans: 3 

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);
}

  1. 15
  2. 23
  3. 40
  4. 30

Answer :

Ans: 2 

 

What is the output of following C program?
#include<stdio.h>
int main()
{
short num[3][2]={3,6,9,12,15,18};
printf(“%d %d”,*(num+1)[1],**(num+2));
return 0;
}

  1. 15,15
  2. 15,9
  3. 9,15
  4. 6,18

Answer :

Ans: 1 

What is the output of following C program?
#include<stdio.h>
int main()
{
int array[2][3]={5,10,15,20,25,30};
int (*ptr)[2][3]=&array;
printf(“%d\t”,***ptr);
printf(“%d\t”,**(*ptr+1));
printf(“%d\t”,*(*(*ptr+1)+2));
return 1;
}

  1. 5,20,25
  2. 5,10,15
  3. 5,20,30
  4. Compile time error

Answer :

Ans: 3 

What is the output of following C program?
#include<stdio.h>
int main()
{
int a[][4]={{10,20,30},{1,2,3,4},{5,6},{7}};
printf(“%d %d %d”,sizeof(a),a[0][2],a[1][2]);
}

  1. Compile time error
  2. 64,30,3
  3. 20,30,3
  4. 32,30,3

Answer :

Ans: 4 , size of array is a[4][4] is of integer type

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

  1. 0,0
  2. Garbage value, Garbage value
  3. 10, garbage value
  4. Compile time error

Answer :

Ans: 1 , If we initialize the array atleast with one element, reamining elements initializes with zeros

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

  1. 18,2,4
  2. 36,2,4
  3. 12,0,5
  4. 18, 0, 5

Answer :

Ans: 4 

Arrays – Objective – Part 1

Share this