C Technical Interview Questions on Arrays

These C Technical Interview Questions on Arrays Part2 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>
int main()
{
char *s[10] = {“Welcome”, “to”, “Java2Python”};
int i = 0;
for (i = 0 ; i<3; i++)
printf(“%c”, **(s+i));
return 1;
}

  1. Welcome to Java2Python
  2. Garbage character, Garbage character, Garbage character
  3. WtJ
  4. Compile time error

Answer :

Ans: 3 , We are printing every word first character using %c

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

  1. Compile time error
  2. 1
  3. Garbage value
  4. a

Answer :

Ans: 1 , We cannot initialize the values in such a way

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

  1. Compile time error
  2. 30
  3. Garbage value
  4. 31

Answer :

Ans: 4 

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

  1. 16
  2. 15
  3. 25
  4. 24

Answer :

Ans: 3

What is the output of following C program?
#include<stdio.h>
int main()
{
int a;
char b;
int arr[sizeof(!a+b)];
printf(“%d”,sizeof(arr));
return 0;
}

  1. 4
  2. Compile time error
  3. 2
  4. 3

Answer :

Ans: 1, arr[2] size if finds

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

  1. Compile time error
  2. 60
  3. 50
  4. 40

Answer :

Ans: 3 

What is the output of following C program?
#include<stdio.h>
int main()
{
float arr[ ] = {12.4, 2.3, 4.5, 6.7};
printf(“%d\n”, sizeof(arr)/sizeof(arr[0]));
return 0;
}

  1. 8
  2. 4
  3. 2
  4. Compile time error

Answer :

Ans: 2 , size of arr is 16 and size of arr[0] is 4

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

  1. 0
  2. 1
  3. 3
  4. 2

Answer :

Ans: 4 

What is the output of following C program?
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf(“%d, %d, %d”, i, j, m);
return 0;
}

  1. 1,5,15
  2. 3,2,15
  3. 2,5,15
  4. Compile time error

Answer :

Ans: 2 

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

  1. 0
  2. Garbage value
  3. Compile time error
  4. None of the above

Answer :

Ans: 3

Arrays – Technical – Part 3

Share this