Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

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)

Principles of Programming Languages:

EasyExamNotes.com covered following topics in these notes.

Practicals:
Previous years solved papers:

A list of Video lectures

References:

  1. Sebesta,”Concept of programming Language”, Pearson Edu 
  2. Louden, “Programming Languages: Principles & Practices” , Cengage Learning 
  3. Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill. 
  4. E Horowitz, “Programming Languages”, 2nd Edition, Addison Wesley 

Leave a Comment