Pointers in C
Q1. Define pointers.
Answer:
Pointers are the variables that can store the memory address of another variable.
Q2. What is the difference between a constant pointer and a pointer to a constant?
Answer:
A constant pointer points to the fixed memory location, i.e. we cannot change the memory address stored inside the constant pointer.
On the other hand, the pointer to a constant point to the memory with a constant value.
Q3. What is pointer to pointer?
Answer:
A pointer to a pointer (also known as a double pointer) stores the address of another pointer.
Q4. Does pointer size depends on its type?
Answer:
No, the pointer size does not depend upon its type. It only depends on the operating system and CPU architecture.
Q5. What are the differences between an array and a pointer?
Answer:
The following table list the differences between an array and a pointer:
Pointer
Array
A pointer is a derived data type that can store the address of other variables. An array is a homogeneous collection of items of any type such as int, char, etc. Pointers are allocated at run time. Arrays are allocated at runtime. The pointer is a single variable. An array is a collection of variables of the same type. Dynamic in Nature Static in Nature.
Q6. Why do we need to specify the type in the pointer declaration?
Answer:
Type specification in pointer declaration helps the compiler in dereferencing and pointer arithmetic operations.
Quizzes:
C Pointers
Pointers are one of the core components of the C programming language. A pointer can be used to store the memory address of other variables, functions, or even other pointers. The use of pointers allows low-level memory access, dynamic memory allocation, and many other functionality in C.
In this article, we will discuss C pointers in detail, their types, uses, advantages, and disadvantages with examples.