Sunday 27 August 2017

APTITUDE QUESTION



1) Which operator is used to get the "content of a variable pointed to by a pointer"?

1.Dot Operator (.)
2.Address of Operator (&)
3.Indirection or De-reference Operator (*)
4.Arrow Operator (→)
Answer & Explanation:
Correct answer: 3
Indirection or De-reference Operator (*)


2) What will be the type of a pointer, which is pointing to an integer variable?

1.int *
2.long int *
3.char *
4.unsigned *
Answer & Explanation:
Correct answer: 1
int *
 To store the address of an integer variable, we need to declare an integer pointer (int *).


3) If ptr is a pointer to one dimensional array, which statement will return the value of 3rd element?

1.(ptr+3)
2.*(ptr+3)
3.(&ptr+3)
4.*ptr+3
Answer & Explanation:
Correct answer: 2
*(ptr+3)
 ptr will point to the address of one-dimensional array and * (indirection or de-reference operator) returns the value of variable pointed by a pointer, thus *(ptr+3) will return the value of 3rd element of array.


 4) Consider the given declaration:

int* ptr1,ptr2;
What is the type of ptr2 here?

1.int * (Integer pointer)
2.void
3.void * (void pointer)
4.int (integer)
Answer & Explanation:
Correct answer: 2
int (integer)
 Here, compiler will ignore the pointer asterisk, when carrying a type over to multiple declarations. If we split the declarations of ptr1 and ptr2 into multiple declarations, compiler will consider them like:
 int *ptr1;
int ptr2;
Thus, ptr is not int*, it is int type variable.


5) What will be the correct way to declare two integer pointers using single line declaration?

1.int *ptr1,*ptr2;
2.int* ptr1,ptr2;
3.int * ptr1, ptr2;
4.All of the above
Answer & Explanation:
Correct answer: 1
int *ptr1,*ptr2;
 It is possible to declare multiple pointers in a single line declaration, use asterisk (*) before the pointer names.


6) Consider the following statement:

int arr[5],*ptr;
How to initialize ptr with the address of array arr?

1.ptr = arr;
2.ptr = &arr[0];
3.ptr = &arr;
4.Both 1) and 2)
Answer & Explanation:
Correct answer: 4
Both 1 and 2
 A pointer to an array of integers can be initialized using array name (arr) or base address of first array element .



 



4 comments:

  1. Hi C Programming Team,

    My name is Anuj Agarwal. I'm Founder of Feedspot.

    I would like to personally congratulate you as your blog C Programming has been selected by our panelist as one of the Top 25 C Programming Blogs on the web.

    https://blog.feedspot.com/c_programming_blogs/

    I personally give you a high-five and want to thank you for your contribution to this world. This is the most comprehensive list of Top 25 C Programming Blogs on the internet and I’m honored to have you as part of this!

    Also, you have the honor of displaying the badge on your blog.

    Best,
    Anuj

    ReplyDelete
  2. Nice post.
    For more information on C programming, visit https://verkkonet.com/blog/c-program-without-main-function/?unapproved=588&moderation-hash=cfd8131d3ee034ffb2fa4383673e1454#comment-588

    ReplyDelete
  3. React.js offers a faster development environment, and its very easy to use. Learn them without taking care of too many setups, when you are developing apps by serving HTML files.
    Learn How to Use Reactjs Cdn

    ReplyDelete