- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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;
Advertisements