Pointers
Pointers are the variables that store the address of another variable. They can point to any data type in C
Syntax of Pointers
data_type * ptr_name;
Note: The addressof (&) operator is used to get the address of a variable.
We can dereference (access the value pointed by the pointer) using the same * operator.
Example of Pointers
C
// C program to illustrate Pointers #include <stdio.h> // Driver program int main() { int var = 10; // declare pointer variable int * ptr; // note that data type of ptr and var must be same ptr = &var; // assign the address of a variable to a pointer printf ( "Value at ptr = %p \n" , ptr); printf ( "Value at var = %d \n" , var); printf ( "Value at *ptr = %d \n" , *ptr); return 0; } |
Value at ptr = 0x7ffd62e6408c Value at var = 10 Value at *ptr = 10
There are different types of pointers based on different classification parameters. Some of them are:
- Double Pointers
- Function Pointers
- Structure Pointers
- NULL Pointers
- Dangling Pointers
- Wild Pointers
C Cheat Sheet
This C Cheat Sheet provides an overview of both basic and advanced concepts of the C language. Whether you’re a beginner or an experienced programmer, this cheat sheet will help you revise and quickly go through the core principles of the C language.
In this Cheat Sheet, we will delve into the basics of the C language, exploring its fundamental concepts that lay the groundwork for programming. We will cover topics such as variables, data types, and operators, providing you with a solid understanding of the building blocks of C programming.
Contact Us