Search Placementyogi.com
 

Difficult Pointers objective questions in C

  :: Topics ::

1

Each printf statement prints 2 addresses. Select the line in which 2 addresses are same.

#include<stdio.h>
int main()
{
  int a[6]={1,2,3,4,5,6};
  printf("%ul,%ul,",a,&a);   //Line 1
  printf("%ul,%ul,",a+1,&a+1); //Line 2 
  printf("%ul,%ul",a+6,&a+1);//Line 3

}
A.

Only Line 1

B.

Only Line 2

C.

Line 1 and Line 2

D.

Line 1 and Line 3

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation
a and &a are NOT the same, they have different types, but hold the same memory address.
 
 &a is of type int (*)[6]  (address of array same as address of first element)
 a is of type int [6]        (address of first element)
 
When we do a+1, it increments address by 4 bytes(assuming size of int is 4 bytes) but when we do &a+1, increments address by 24 bytes(size of array).  
 
Note : An array is not a pointer. It evaluates to a pointer in almost all context,but there are two exceptions to this:when the array name is an operand of sizeof or unary & (address-of), the name refers to the array object itself. Thus sizeof array gives you the size in bytes of the entire array, not the size of a pointer.
 
2

Which program is correct?

/*Program 1*/
#include<stdio.h>
int main()
{
  int  a[2][3]={1,2,3,4,5,6};
  int (*ptr)[3]=a; //Line 5
  printf("%d,%d",a[1][2],*(*(ptr+1)+2));
}

/*Program 2*/
#include<stdio.h>
int main()
{
  int  a[2][3]={1,2,3,4,5,6};
  int **ptr=a;   //Line 5
  printf("%d,%d",a[1][2],*(*(ptr+1)+2));
}
A.

Both are correct, output => 6 , 6

B.

Program 1 is correct, output => 6

C.

Program 2 is correct, output = > 6

D.

Both are wrong

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

No explanation available. Let's Discuss

 
 

Banner to LogicGuns.com

Hide Page Information

C Difficult Pointers Objective Questions and Answers for Written Round Interview

Here you can find C Difficult Pointers Objective Questions with answers and explanation. We have a vast collection of Objective Questions on Difficult Pointers in C that will help you a lot!

Why learn C Difficult Pointers?

Difficult Pointers are an integral part of C and many Objective Questions in the written round are asked from this topic.In this section you can learn and practice C Difficult Pointers (Objective Questions 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 Difficult Pointers Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Difficult Pointers Objective Questions 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 Difficult Pointers, We have quiz Objective Questions with answers to help you test yourself..

\n

Where can I get C Difficult Pointers Interview Objective Questions and Answers (objective type, multiple choice)?

Here you can find objective type C Difficult Pointers Objective Questions and answers for interview and entrance examination.Multiple Answers and true or false type Objective Questions are also provided.

How to solve C Difficult Pointers problems?

You can easily solve all kind of Objective Questions based on C Difficult Pointers by practicing the exercises (including shortcut Difficult Pointers to solve problems) given below.