C Pointer Interview Questions and Answers

This “C Pointer interview questions” post is providing all the frequently asked questions on pointers from basic to expert level to test yourself.


 

What is a Pointer ?

  • A derived data type.
  • A pointer variable can store the address(memory location) of another variable.

What is the use of Pointer variable ?

  • Used to access the information by holds its address.
  • It is also called in-direction operator.

 

What is the size of pointer ?

  • Size of pointer is equals to size of integer on the machine.
  • On 16 bit compiler, pointer size is 2 bytes.

What is void pointer ?

  • void* is called Generic pointer.
  • void* variable can holds any pointer type value.

What is Call by Value ?

  • Calling a function by passing values as parameters is called Call by Value.

What is Call by Reference?

  • Calling a function by passing address(reference) as parameter.
  • We collect these addresses into pointer type variables in the called function.

What pointer operator(*) returns ?

  • Pointer operator returns the data of specified memory location.

Can we create a pointer to function ?

  • Functions execute at a particular memory location is called FRAME.
  • Every FRAME has a address.
  • Pointer to function variable holds that address to execute function.

How to declare pointer to function ?

  • Pointer to function declaration depends on the prototype of function.
    Syntax :
    return_type (*identifier) (arguments_list) ;


What is Dangling pointer ?

  • Declaration of pointer variable that holds the address of local variable of another function.
  • Dangling pointers will not generate 100% accurate results in the application.

What is pointer casting ?

  • Converting data at runtime is type-casting.
  • One typed pointer cannot point to another type of data.
  • If we want to point one type of data using another type of pointer, we can apply pointer casting.

What is pointer arithmetic ?

  • When we modify integer, the value either increased/decreased by 1.
  • When we modify the pointer variable, the size of pointer increases/decreases by size bytes of data which is currently pointing to.

Can we apply modify operators on pointer variable ?

  • Yes we can.
  • Using modify operators only we can process array elements effectively.

Define Array of Pointers ?

  • Array of Pointers means an Array which is holding
    1) References of same array elements
    2) Reference of different array elements


What is the use of Array of Pointers ?

  • We can easily process the information like Set of String elements.
  • We can process Multi dimensional array data.
  • We can connect number of arrays with single address variable.

Can we create pointer to Structure?

  • Yes.
  • When a pointer is pointing to structure, we use Arrow(->) operator to access the elements of structures instead of dot(.) operator.

How to access structure elements using pointer ?

  • Using Arrow(->) operator.
  • Generally we use dot(.) operator to access structure elements.

What char* represents in C ?

  • char* can points
    1) a single character
    2) array of characters(string)


Can a function returns Array using pointers ?

  • Yes.
  • A function can returns array only by using pointers.
  • A function can return address so that return type is pointer type.

Can a function returns String using char* ?

  • Yes, we can return Strings from functions only by returns base address of that String.

What is the use of Pointer to Pointer ?

  • Easily we can process the elements which are connected.
    for example Linked Lists.


Describe this pointer declaration ? [​int (* ptr) (int,int)]

  • “ptr” is a pointer, pointing to a function which is taking 2 integer arguments and returns integer data.

 

Describe this pointer declaration ? [char (* ptr) [3]]

  • “ptr” is a pointer pointing to array of size is 3 and the array is holding character elements.

Describe this pointer declaration ? [​int ( * ( * ptr ) [ 5 ] ) ( )]

  • “ptr” is pointer variable which is pointing to an array which is holding address of 5 functions and each function is not taking input but returns integer.

 

>C Language Basic Interview Questions<

Share this