Search Placementyogi.com
 

Arrays In C Advanced Objective Questions and Answers

  :: Topics ::

1

What is the output of the following program?

#include<stdio.h>
void main()
{
    int a=5,b=10,c=15;
    int *arr[3]={&a,&b,&c};
    printf("%d",*arr[*arr[1]-8]);
}
A.

15

B.

10

C.

5

D.

Error: Array index cannot be an expression

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

arr is an array of pointer to integers.

arr[0] contains the address of the variable "a"

arr[1] contains the address of the variable "b"

arr[2] contains the address of the variable "c"

Now, Consider the expression: *arr[*arr[1]-8]

*arr[1] contains the value of "b"  i.e. 10

*arr[1]-8

= 10-8 

= 2

Now the expression becomes: *arr[2] i.e. the value at the address contained in arr[2] ,i.e. value of c

Hence the answer is 15.

 
2

What is the output of the following program?

Assume,

Base address of a is 1000

Address of p is 2000

Address of q is 3000

#include<stdio.h>
void main()
{
	int a[]={0,1,2,3,4,5};
	int *p[]={a,a+1,a+2,a+3,a+4,a+5};
	int **q=p;
	printf("%u",a);
	printf("%u %u %d %d",p,&p,*p,**p);
	printf("%u %u %d %d",q,&q,*q,**q);
}
A.

1000 1000 2000 1000 0 2000 3000 1000 0

B.

1000 2000 2000 1000 0 2000 3000 1000 0

C.

1000 2000 2000 1000 0 2000 3000 2000 0

D.

None of the Above

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

p is an array of pointers and contains the address of elements of the array.

q is a pointer to a pointer and contains the address of p.

The following picture speaks it all!

array of pointers

 

 

 

 

 

 

 

 

 

Here, p[0] contains 1000 (address of a[0]),

p[1] contains 1004 (address of a[1]) and so on. 

p=1000 (the value inside the box)

address of p (&p) is 2000 (The value below the box)

q=2000 (the value inside the box)

address of q (&q) is 3000 (The value below the box)

 
 
 

Banner to LogicGuns.com

Hide Page Information

C Arrays Advanced MCQs and Answers for Written Round Interview

Here you can find C Arrays Advanced MCQs with answers and explanation. We have a vast collection of MCQs on Arrays Advanced in C that will help you a lot!

Why learn C Arrays Advanced?

Arrays Advanced are an integral part of C and many MCQs in the written round are asked from this topic.In this section you can learn and practice C Arrays Advanced (MCQs with Answers) to improve your skills in order to face the interview and clear campus and off-campus selection of TCS, Infosys, Wipro etc.

Where can I get C Arrays Advanced MCQs and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Arrays Advanced MCQs and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand.Though we do not have pdf file for C Arrays Advanced, We have quiz MCQs with answers to help you test yourself..

\n

Where can I get C Arrays Advanced Interview MCQs and Answers (objective type, multiple choice)?

Here you can find objective type C Arrays Advanced MCQs and answers for interview and entrance examination.Multiple Answers and true or false type MCQs are also provided.

How to solve C Arrays Advanced problems?

You can easily solve all kind of MCQs based on C Arrays Advanced by practicing the exercises (including shortcut Arrays Advanced to solve problems) given below.