- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pointers in C/C++
Basically, pointers are variables which stores the address of another variable. When we allocate memory to a variable, pointer points to the address of the variable. Unary operator ( * ) is used to declare a variable and it returns the address of the allocated memory.
The following is the syntax of pointers.
datatype *variable_name;
Here,
datatype − The datatype of variable like int, char, float etc.
variable_name − This is the name of variable given by user.
The following is an example of pointers.
Example
#include <stdio.h> int main () { int a = 8; int *ptr; ptr = &a; printf("Value of variable : %d\n", a); printf("Address of variable : %d\n", ptr); printf("Value pointer variable : %d\n",*ptr); return 0; }
Output
Value of variable : 8 Address of variable : -201313340 Value pointer variable : 8
In the above program, an integer variable ‘a’ and a pointer variable ‘*ptr’ is declared. The variable value and address stored by the pointer variable are shown as follows −
int a = 8; int *ptr; ptr = &a;
- Related Articles
- Pointers, smart pointers and shared pointers in C++
- Applications of Pointers in C/C++
- What are Wild Pointers in C/C++?
- How to compare pointers in C/C++?
- Pointers vs References in C++
- What are pointers in C#?
- RAII and smart pointers in C++
- C/C++ Pointers vs Java references\n
- When to use references vs. pointers in C/C++
- Dangling, Void, Null and Wild Pointers in C/C++
- near, far and huge pointers in C
- Difference between Array and Pointers in C.
- Why are NULL pointers defined differently in C and C++?
- Dangling, Void, Null and Wild Pointers in C++
- Explain Arithmetic operations using pointers in C language?

Advertisements