Article by: Manish Methani
Last Updated: October 20, 2021 at 2:04pm IST
int i = 3 ;
Compiler will tell the memory to store value 3 at some location and name that location as 'i' .It looks like this ,
Diagram itself is explanatory. The value of 'i' is 3 and it is stored at some location Number . You don't have to worry about the location Number . Memory will automatically handle this.
#include <iostream> using namespace std; int main() { int a = 5; cout <<"Address of variable a = "<< &a <<endl; cout<<"Value of variable a = "<<a <<endl ; cout<<"Value of variable a = "<< *(&a); return 0; }
Address of variable a = 12345678 Value of variable a = 5 Value of variable a = 5
* asterik indicates that the variable is pointer variable. The third cout statement
cout<<"Value of variable a = "<< *(&a);
Here , first we get the address of variable 'a' using &a and apply that address * to get the value at that specific address.
Pointers are used to get the value at specific address Simple and Easy Defination. Pointers are denoted by *(Asterik symbol).
datatype *variableName;
int *a; float *b; float **b; float ***b;
int i=3; j = &i;
Always read * as "Value at"
Assume 1000 & 1004 are the addresses of i & j i 1000 --> 3 j 1004 --> 1000 *j --> Read Value at j Value at 1000 What is the value at 1000 Address ? :) *j --> 3 /* Yes you have to read the pointers like this. */
#include <iostream> using namespace std; int main() { int i=3, *j, k; j = &i; cout<< i * *j * i + *j; return 0; }
30
Compute the value of j like i explained in above example.
i = 3
*j = 3
i * *j * i + *j
3 * 3 * 3 + 3 = 30
This statement allocates memory to store the value 3 at a certain location named "i".
Pointers are denoted by the asterisk symbol `*`. They are variables used to access values at specific addresses in memory.
The asterisk symbol `*` is used to declare pointer variables and to access the value at a specific memory address.
Pointers hold the memory address of another variable. By using the `*` symbol, they can access and manipulate the value stored at that address.
The `&` operator is used to get the memory address of a variable in C++.
FlutterFlow Course from Basic to Advanced
Flutter App Development Course in Hindi
Contact: teamcodzify@gmail.com
GSTIN: 27CTSPM6231L1Z0 - Registered under Goods and Services Tax