Sunday, 17 December 2017

Pointer

Ques 1) What are pointers ?

Ans--> pointers are the variable that hold memory address of another variable.

Ques 2) What are the special operators used in pointers ?

Ans-->The two special operators used in pointers are * and &.
          & is an unary operator that return the memory location of its operand.
          * is a complement of & operator is also a unary operator that returns the            value of the variable located at the address that follow.

Ques 3) Const Char *p, char const *p What is the difference between the above two ?

Ans--> Const char *p : This is a pointer to a constant character. Here, we cannot change the value pointed by p, but we can change the pointer p itself.

char Const *p : This is also pointer to a constant character.

Ques 4) What is the difference between const char *p, char *const p, const char * const p ?

Ans--> char * const p: This is constant pointer to a non constant character.Here, we cannot the pointer p itself, but we can change the value pointed by p.

const char *const p: This is a constant pointer to a constant. Here, we cannot change the pointer p nor the value pointed by p.

const char *p: This is a pointer to a constant character. Here, we cannot change the value pointed by p, but we can change the pointer p itself.

Ques 5) What are function pointers ?

Ans--> Function pointers are the variables that stores the address of the function, that can be latter called through that function pointers.

Ques 6) What are the different types of constant pointers ?

Ans--> i) A non-constant pointer to a constant data.
           ii) A constant pointer to a non-constant data.
           iii) A constant pointer to a constant data.

Ques 7) What  arithmetic operations are permitted on pointers ?

Ans--> i) Addition and subtraction of an integer from pointer.
           ii) Subtraction of pointer variable from another.
( One pointer variable can be subtracted from another pointer provided both pointers point to the same data type or both pointers points to the element of same array )

Ques 8) What arithmetic operations are not allowed in pointers ?

Ans--> i) addition of two pointers.
           ii) Multiplication of pointer variable by a number.
           iii) Division of pointer variable by a number.

Ques 9) What is dangling pointer or wild Pointer ?

Ans-->Dangling pointers are the pointer pointing to a dead location or some arbitrary location or uninitialized pointers are called wild pointers.

Ques 10) When would dangling pointer happen ?

Ans--> i) When a pointer is pointing to an object which is dead.
           ii) not initializing the pointer.
           iii) returning address of local variable from a function.

Ques 11) How to avoid dangling pointer ?

Ans-->i) By initializing the pointer to the variable address or by Null.
          ii) By initializing the pointer to NULL as soon as the object to which it point is dead.
          iii) By not returning the address of local variable from the function.

Ques 12) What is the size of pointer ?

Ans-->2 byte( 16 bit compiler) and 4 byte (32 bit compiler) Because pointer just holds the address of memory location.

Ques 13) What are the application of pointers ?

Ans--> i) Call By address.
           ii) passing an entire array to a function.
           iii) Dynamic Memory Allocation.
           iv) For returning more than one value from a function.

Ques 14) What is NULL pointers ?

Ans-->Null pointer is a pointer that points to no where i.e. points to nothing. Pointers that are initialized with NULL value is considered as NULL pointers.

Ques 15) What are void pointer ?

Ans-->void pointer are the pointers that don't have any type associated with them and can have address of any type of variable.
Syntax: void *p

The pointer to void cannot be directly dereference like other pointer variable by using prior dereferencing, pointer to void must be typecasted to required data type.






           


No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...