Pointers - C Questions

Pointers Questions - 1 Pointers Questions - 2 Pointers Questions - 3 Pointers Questions - 4 Pointers Questions - 5 Pointers Questions - 6 Pointers Questions - 7 Pointers Questions - 8

Data Types - C Questions

Data Types Questions - 1 Data Types Questions - 2 Data Types Questions - 3 Data Types Questions - 4 Data Types Questions - 5

Operators - C Questions

Operators Questions - 1 Operators Questions - 2 Operators Questions - 3 Operators Questions - 4 Operators Questions - 5

Structures - C Questions

Structures Questions - 1 Structures Questions - 2 Structures Questions - 3 Structures Questions - 4 Structures Questions - 5

Files - C Questions

Files Questions - 1 Files Questions - 2 Files Questions - 3 Files Questions - 4 Files Questions - 5

printf - C Questions

printf Questions - 1 printf Questions - 2 printf Questions - 3 printf Questions - 4 printf Questions - 5

Variables - C Questions

Variables Questions - 1 Variables Questions - 2 Variables Questions - 3 Variables Questions - 4 Variables Questions - 5

Preprocessor Macros

Preprocessor Macros - 1 Preprocessor Macros - 2 Preprocessor Macros - 3 Preprocessor Macros - 4 Preprocessor Macros - 5

While Loop - C Questions

While Loop Questions - 1 While Loop Questions - 2 While Loop Questions - 3 While Loop Questions - 4 While Loop Questions - 5

for Loop - C Questions

for Loop Questions - 1 for Loop Questions - 2 for Loop Questions - 3 for Loop Questions - 4 for Loop Questions - 5

if else - C Questions

if else Questions - 1 if else Questions - 2 if else Questions - 3 if else Questions - 4 if else Questions - 5

Switch case - C Questions

Switch case Questions - 1 Switch case Questions - 2 Switch case Questions - 3 Switch case Questions - 4 Switch case Questions - 5

Array - C Questions

Array Questions - 1 Array Questions - 2 Array Questions - 3 Array Questions - 4 Array Questions - 5

Functions - C Questions

Functions Questions - 1 Functions Questions - 2 Functions Questions - 3 Functions Questions - 4 Functions Questions - 5

Memory Allocation

Memory Allocation - 1 Memory Allocation - 2
The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Interview Array Questions

In most of the MNC interview questions such as in ZOHO interview question, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, We come across several Tricky C Questions about which 2:5 of the questions are from Array in c. Solving that kind of tricky C questions is not an easy task for all C programmers. We need more practices to solve it with ease. So we provide 25+ interesting C questions in Array to make your MNC interview very easy.

C Array Questions

6. What will be the output of the C program?

#include<stdio.h>
int main()
{
	int arr[5][5][5] = {0};
	printf("%d", ( &arr+1 - &arr ));
	return 0;
}

A. 0

B. Compilation error

C. 1

D. 4

x

 

Option: C

Explanation

printf("%d", (&arr+1 - &arr)); let us consider the address of an array arr starts from 2293420
then, printf("%d", (2293420 +1 - 2293420);
printf("%d", 0 + 1);
printf("%d", 1);
Thus 1 is outputted.

Answer


7. What will be the output of the C program, if input is 6?

#include<stdio.h>
void fun(int[][3]);
int main(void)
{
	int arr[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
	fun(arr);
	printf("%d\n", arr[2][1]);
	return 0;
}
void fun(int b[][3])
{
	++b;
	b[1][1] = 15;
}

A. 15

B. 9

C. 8

D. 7

x

 

Option: A

Explanation

This question from 2braces.com is more tricky.
fun(arr) returns the address of first element in an array to the function void fun();
Let us consider the address of the values in arr[3][3] is 2293420.
when it passes through the function void fun(int b[][3]), its value is pre-incremented ++b
As it is a multi dimensional array ++b will not skip the address next to the last value in an array arr[][3] instead it skip the address next to first part only i.e) now b[][3] array starts with the address 2293432 (i.e) starts from the value 4 but index from 0, Clearly b[0][0] = 4
Now b[1][1] = 15 will affect the value 8 in arr of array.
Thus arr[2][1] outputted 15.

Answer


8. What will be the output of the C program by considering 'b' as a User input?

#include<stdio.h>
int main(){
	int rows = 3, colums = 4, i, j, k;
	int a[3][4] = {1, 2, 3, 5, 7};
	i = j = k = 00;
	for(i = 0;i<rows;i++)
	for(j = 0;j<colums;j++)
	if(a[k][j]<k)
	k = a[i][j];
	printf("%d\n", k);
	return 0;
}

A. 00

B. No output

C. 0

D. 7

x

 

Option: C

Explanation

Initially we set i = 0, j = 0, k = 0. zero be never greater than any integer values in an array a[3][4], thus if condition fails. and 0 is outputted.

Answer


9. What will be the code to print 5 contains in a[4][1][0]?

#include<stdio.h>
int main()
{
	int arr[ ]={1.2, 2.4, 3.6, 4.8, 5};
	int j, *ptr = arr;
	for(j = 0;j<5;j++)
	{
	printf("%d ", *arr);
	++ptr;
	}
}

A. 2 2 2 2 2

B. 1 1 1 1 1

C. 1 2 3 4 5

D. None of the above

x

 

Option: B

Explanation

Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr. So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.

Answer


10. What will be the output of the C program?

#include<stdio.h>
int main()
{
	int arr[5][5][5] = {0};
	int *b = arr;
	int *c = arr + 1;
	printf("%d", c - b);
	return 0;
}

A. 0

B. Runtime Error

C. 25

D. Some address

x

 

Option: C

Explanation

Clearly array arr[5][5][5] can hold upto 25 integer values.
let us consider the address of first element in an array arr[5][5][5] is 2292932
Now *b = 2292932; *c = arr + 1; i.e) *c contains the address which is located next to the last value address in an arr[5][5][5], which is the address location next to that 25th value in an array arr[5][5][5].
Now *c = 2293032;
here, printf("%d", c-b);
printf("%d", 2292932 - 2293032);
printf("%d", 100); this is not yet over
printf("%d", 100/ sizeof(int)); as it is an integer type values we have to divide it by sizeof(int) to display value not the address.
printf("%d", 25);
thus 25.

Answer


Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report

We to update you