In the C programming language, in addition to basic data types such as int, float, char, and double, there are derived data types that are based on basic types, but offer additional capabilities and flexibility when working with data. Derived data types are types that extend the functionality of primitive types by combining or referencing existing data. They allow the programmer to efficiently manage memory, group data, or define operations. Unlike primitive types, which directly store values, derived types often involve indirection, such as pointers, or the organization of multiple elements, such as arrays.
The main derived data types in the C language are:
Pointers: A data type that stores a memory address, e.g., int*, char*
Arrays: A collection of elements of the same type, e.g., int arr [10]
Functions: The return value type of a function, e.g., int function ())
As you can see, in the C programming language, the main derived data types are pointers, arrays, and functions, and user-defined types such as struct, union, and enum are often implicitly included in this category, although they are formally different. We will write about user-defined types in the next blog post. Now we will concentrate only on derived data types that are not user-defined. If you are wondering how functions are a derived data type, then you simply need to know that functions in the C programming language have a type defined by their return value. They are not variables in the classical sense, but they are considered derived types because they allow defining operations on data. We hope this has cleared up any confusion. If anything is unclear, ask in the comments or contact us personally via the contact form on our blog.
Pointer Declaration:
int *ptr;
This means that ptr is a pointer to an integer value, int type specifies the type of data the pointer points to e.g., int, float, char, while * indicates that this is a pointer.
Key Operators:
& Address-of Operator - Retrieves the memory address of a variable.
* Dereference Operator - Accesses or modifies the value at the address stored in the pointer.
Initialization Example:
int number = 10;
int *ptr = &number; // ptr points to the address of the number variable
Pointer Dereferencing:
printf("Value at address:
%d\n", *ptr); // Prints 10
Dereferencing means accessing the value at the address that the pointer points to. Arrays in the C programming language are actually pointers to the first element. You can use them to traverse the array. Pointers can be used to pass arguments to functions to allow modifications of the original values. Function pointers allow functions to be called dynamically, based on their address. A pointer can also point to another pointer, allowing multiple levels of indirection. In any case, you will master pointers most easily through practice and coding.
Understanding and Applying Pointers in a Practical Example in C Programming Language
