C Programming Interview Questions Set 4

Categories: C Programming language

Ques. What is a far pointer in C?

Ans. A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given section.


Ques. What is dangling pointer in C?

Ans. a) If a pointer is pointing any memory location, but meanwhile another pointer deletes the memory occupied by the first pointer while the first pointer still points to that memory location, the first pointer will be known as a dangling pointer. This problem is known as a dangling pointer problem.

b) Dangling pointer arises when an object is deleted without modifying the value of the pointer. The pointer points to the deallocated memory.

Let's see this through an example.


#include<stdio.h>  

void main()  

{  

        int *ptr = malloc(constant value); //allocating a memory space.  

        free(ptr); //ptr becomes a dangling pointer.  

}  


Ques. What is pointer to pointer in C?

Ans. In case of a pointer to pointer concept, one pointer refers to the address of another pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains the address of a variable. The pointer to pointer contains the address of a first pointer. Let's understand this concept through an example:


#include <stdio.h>  

 int main()  

{  

    int a=10;  

    int *ptr,**pptr; // *ptr is a pointer and **pptr is a double pointer.  

    ptr=&a;  

    pptr=&ptr;  

    printf("value of a is:%d",a);  

    printf("\n");  

    printf("value of *ptr is : %d",*ptr);  

    printf("\n");  

    printf("value of **pptr is : %d",**pptr);  

    return 0;  

}  

In the above example, pptr is a double pointer pointing to the address of the ptr variable and ptr points to the address of 'a' variable.


Ques. What is static memory allocation?

Ans. a) In case of static memory allocation, memory is allocated at compile time, and memory can't be increased while executing the program. It is used in the array.

b) The lifetime of a variable in static memory is the lifetime of a program.

c) The static memory is allocated using static keyword.

d) The static memory is implemented using stacks or heap.

e) The pointer is required to access the variable present in the static memory.

f) The static memory is faster than dynamic memory.

g) In static memory, more memory space is required to store the variable.

For example:  

int a[10];  

The above example creates an array of integer type, and the size of an array is fixed, i.e., 10.

Top Blogs
C Functions ! What is a Function Published at:- Types of Function in C ! Library Function in C ! User Defined Function In C ! Function Definition Published at:- Functions that return multiple values -C Example Published at:- Functions with arguments and return values -C Examples Published at:- Functions with arguments and no return values. Published at:- Example of Function with no return type and no argument Published at:- Loops in C Published at:- Structure in C: Introduction Published at:- C Memory Management ! Dynamic memory allocation Published at:- Learn C Programming language with example Published at:- C Interview Questions And Answers Published at:- What values are printed when we run following? Published at:- C Program example: Input a number and print sum of its digits Published at:- Pointer declaration in C ,Address operator Published at:- C Language Interview Question and Answers Published at:- Benefits of C language over other programming languages Published at:- History of C Language : Introduction to C Programming Language Published at:- How does C Programming Language Work Published at:- Importance of C Programming Language Published at:- Input and Output Functions in C Published at:- Introduction to Implementation of Queue using Linked List Published at:- First C Program Published at:- Inception Of C Language Tutorial for Beginners Published at:- The C Compiler work in C language and its important Published at:- Program Structure with “Hello World” Example Published at:- C Programming Interview Questions Set 1 Published at:- C Programming Interview Questions Set 2 Published at:- C Programming Interview Questions Set 3 Published at:- C Programming Interview Questions Set 4 Published at:- C Programming Interview Questions Set 5 Published at:- C Programming Interview Questions Set 6 Published at:- C Programming Interview Questions Set 7 Published at:- C Programming Interview Questions Set 8 Published at:- C Programming Interview Questions Set 9 Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.