

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to declaring pointer variables in C/C++?
A pointer is used to store the address of the variables. To declare pointer variables in C/C++, an asterisk (*) used before its name.
Declaration
*pointer_name
In C
Example
#include <stdio.h> int main() { // A normal integer variable int a = 7; // A pointer variable that holds address of a. int *p = &a; // Value stored is value of variable "a" printf("Value of Variable : %d\n", *p); //it will print the address of the variable "a" printf("Address of Variable : %p\n", p); // reassign the value. *p = 6; printf("Value of the variable is now: %d\n", *p); return 0; }
Output
Value of Variable : 7 Address of Variable : 0x6ffe34 Value of the variable is now: 6
In C++
Example
#include <iostream> using namespace std; int main() { // A normal integer variable int a = 7; // A pointer variable that holds address of a. int *p = &a; // Value stored is value of variable "a" cout<<"Value of Variable : "<<*p<<endl; //it will print the address of the variable "a" cout<<"Address of Variable : "<<p<<endl; // reassign the value. *p = 6; cout<<"Value of the variable is now: "<<*p<<endl; return 0; }
Output
Value of Variable : 7 Address of Variable : 0x6ffe34 Value of the variable is now: 6
- Related Questions & Answers
- Double Pointer (Pointer to Pointer) in C
- What is the use of declaring variables in JavaScript?
- How to define pointer to pointer in C language?
- What is the best way of declaring multiple Variables in JavaScript?
- Explain the concept of pointer to pointer and void pointer in C language?
- C program to display relation between pointer to pointer
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- Pointer Arithmetic in C/C++
- NULL pointer in C
- void pointer in C
- Function Pointer in C
- How to declare variables in C#?
- How to define variables in C#?
- How to initialize variables in C#?
- Pointer to an Array in C
Advertisements