Search your topic here

PPL: Pointer & Reference Type

POINTER AND REFERENCE TYPE

Pointer: A pointer is a variable which is used to store the address of another variable.
It is used to allocate memory dynamically at run time.
The pointer variable might be int, float, char, double, short etc.

Pointer syntax:
int *a;

Some points to remember about pointer:
  • Pointer variable stores the address of the variable.
  • The content of the pointer always be a whole number i.e. address.
  • Pointer is initialized to null, i.e. int *a = null.
  • The value of null pointer is 0.
  • & symbol is used to get the address of the variable.
  • * symbol is used to get the value of the variable whose address pointer is holding.
  • Two pointers can be subtracted to know number of elements between these two pointers.
  • Pointer addition, multiplication, division are not allowed.

Pointer example:

int main()
{
   int *p, q;
   q = 10;
   p = &q;
   return *p;
}

What are the design isuues with pointer type?
The design issues for pointer types are 

  • what the scope and lifetime of a pointer variable are, 
  • what the lifetime of a heap-dynamic variable (the value a pointer references) is, 
  • if pointers are restricted as to the type of value to which they can point, 
  • if pointers are used for dynamic storage management, indirect addressing, or both, and 
  • if the language should support pointer types, reference type, or both.


MCQs on Pointer and Reference type

Q1. Pointer is special kind of variable which is used to store __________ of the variable.
a. Value    
b. Address    
c. Variable Name  

Q2. Pointer variable is declared using preceding _________ sign.
a. *
b. %
c. &

Q3. Address stored in the pointer variable is of type __________.
a. Integer
b. Character
c. Array

Q4. In order to fetch the address of the variable we write preceding _________ sign before variable name.
a. Comma
b. Ampersand
c. Asterisk

Q5. "&" is called as ___________ in pointer concept.
a. Address Operator
b. None of these
c. Conditional Operator

Q6. What do the following declaration signify? 
char *arr[4];
a. arr is a array of 4 character pointers.
b. arr is a array of function pointer.
c. arr is a array of characters.



MCQs Answers

Q1. (b)
Q2. (a)
Q3. (a)
Q4. (b)
Q5. (a)
Q6. (a)

LEAVE A REPLY










Related topics

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.