pointers to pointers in cpp

#include <iostream>
using std::cout;

int main() {
  /* 
  Some things to keep in mind:
  	-you shouldn't circumvent the type system if you are creating raw ptrs
  	and don't need to "type pun" or cast (don't use void ptrs)
    -ptr types only reference memory (which are integers), not actual data, thus
    they should not be treated as data types
    char* is just 1 byte of mem, int* is just 4 bytes of mem, etc
    - '*' means that you are creating a pointer which "points" to the mem address
    of a variable
    - '&', in this case, means "get the mem address of this variable"
  */
  
  void* ptr; // a pointer that doesn't reference a certain size of memory
  int* int_ptr; // a pointer that points to data with
  				// only 4 bytes of memory (on stack)
  
  int a = 5; // allocates 4 bytes of mem and stores "5" there (as a primitive)
  ptr = &a; // can only access the memory address of 'a' (not the data there)
  
  int b = 45; 
  int_ptr = &b; // can access both memory address and data of 'b'
  
  cout << ptr << "\n"; // prints mem address of 'a'
  /*cout << *ptr << "\n"; <- this will error out; a void ptr cannot be 
  							 derefrenced */
  cout << *(int*)ptr << "\n"; // type punning to get around void ptr (extra work)
  
  cout << int_ptr << "\n"; // mem address of b
  cout << *int_ptr << "\n"; // data stored at b
  
  /* -- OUTPUTS -- */
  /*
  	some memory address (arbitrary) which contains 05 00 00 00 as its data
  	5
    some memory address (arbitrary) which contains 2D 00 00 00 as its data
    45
  */
  
  return 0; // you only need this if "main" isnt the linker entry point
  			// you also don't care
  
  // ur also probably wondering why I didn't using namespace std... cherno
}

0
0
Avidos 105 points

                                    #include &lt;iostream&gt;
 
using namespace std;
 
int main () {
   int  var;
   int  *ptr;
   int  **pptr;

   var = 3000;

   // take the address of var
   ptr = &amp;var;

   // take the address of ptr using address of operator &amp;
   pptr = &amp;ptr;

   // take the value using pptr
   cout &lt;&lt; &quot;Value of var :&quot; &lt;&lt; var &lt;&lt; endl;
   cout &lt;&lt; &quot;Value available at *ptr :&quot; &lt;&lt; *ptr &lt;&lt; endl;
   cout &lt;&lt; &quot;Value available at **pptr :&quot; &lt;&lt; **pptr &lt;&lt; endl;

   return 0;
}

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c++ pointer function function pointers in cpp how to pass pointers to functions in c++ how often are pointers actually used in c++ use pointer to class function cpp how do pointers work in cpp pointer and function in cpp pointer to function cpp pointer to function with variables cpp pointer and function in c++ should i use pointers in c++ how to declare pointers in c++ how to declare pointer in c+++ pass pointer to function cpp calling a pointer function in c++ declare pointer to value c++ is there pointers in cpp is c++ pointers pointer to pointer object type cpp what is the point of using pointers in c++ cpp pointer applications pointer operations in c++ pointers in c++ definition c++ why use pointers pointers and types of pointers in cpp why use pointers n C++ does c++ have pointers c++ pointers in functions c++ in pointer declare pointers in class in c++ pointer to class in c++ pointer in cpp details pointer function c++ give pointer to function c++ pointer of structure in c++ what must we include to use pointers cpp Pointer and functions with example. in c++ cpp function pointer type reference and pointers c++ function pointer to c++ pointer to function in cpp pointer to pointer ros cpp passing pointers in c++ * pointers cpp different types of pointers in CPP c++ how to use pointers pointers and functions c++ c++ pointer function in class c++ pointer class function pass pointers to functions in c++ pointer to pointer in cpp what is class pointer in c++ pointer declaration in c++ c++ function using pointer to a pointer write a program to implement pointers in c++ when use pointers in c++ c++ pointer to pointer class return pointer to a pointer c++ types of pointers in cpp creating pointer to a class in c++ pointers in c+ pointer definition in cpp using pointers c++ examples convert reference to pointer c++ pointers to pointers in cpp c++ how to have cirkular pointers class pointer in c++ can we return pointer to function in cpp c++ pointer to pointer to pointer Pointer to objects and this pointer to C++ pointers to objects in c++ passing pointer to pointer to function in c++ c++ pointer to reference pointers and addresses in cpp c++ what is this pointer how to use pointers in classes in c++ cpp make a pointer to a pointer c++ declare pointer how to implement pointers in c++ new how to implement pointers in c++ cpp pointer syntax pointer function in c++ passing pointers to functions in cpp states of a pointer in c++ cpp pointers to objects What are pointers in C++. use of new in declaring pointers c++ usage of pointers in c++ how do pointers work in c++ pointers to objects in cpp how to create a pointer to a class in c++ pointer to a class function cpp should you use pointers in c++ reference to a pointer c++ pointers and addresses cpp assign a pointer to a pointer C++ Pointer to objects and this pointer in C++ what's the point of pointers c++ cpp pointer to pointer new pointer of class type in cpp pointer in c++ definition using pointers in functions c++ using pointers through functions c++ c++ pointers examples class pointer in cpp can i create a class pointer in cpp pointer to function in c++ &quot;function&quot; pointer c++ function&quot; pointer c++ using this-&gt; pointer in c++ const pointer to pointer c++ passing pointers to functions in c++ c++ pointer to variable pointer value of c++ class pointer c++ why use pointers in c++ c++ create pointer to function this pointer in c++ example reference to pointer c++ simple pointer program using c++ learn pointers in c++ value of pointer c++ why use pointers to pointers c++ cpp * on pointer pointers constructor in c++ what are pointers in c+++ pointer declaration example in c++ pointers explained c++ function pointer c++ why we use pointers in cpp use of function pointer in c++ what are pointers for c++ c++ cast sthared pointer to pointer how to turn something into a pointer c++ does c++ have pointers how to use pointer methodin class in cpp how to use pointer function in class i cpp this pointer in c++ c++ pointer to a function get pointer to class c++ intro to pointers c++ uses of this pointer in c++ declare pointer as pointer in cpp c++ when to use pointers how to use pointers in c++ this pointer in class c++ &amp; c++ meaning pointers &amp; c++= meaning pointers pointer class in c++ &amp;pointer in cpp c++ send value using pointers cpp create pointer to object assign value to pointer c++ pointer example in c++ pointer pointer variable in c++ create a pointer cpp cpp pointer to value c++ why do we use pointers cpp pointer to the function c++ pointer declaration pointer in c++ example function pointers c++ cpp function pointer pushing values to a pointer of vector cpp c++ set pointer position c++ set cursor position c++ class pointer What is the &ldquo;this&rdquo; pointer in C++? Explain. pointer example in cpp what are pointers used for in c++ c++ are references pointers what is c++ pointers c++ why are pointers useful what is this pointer in c++ c++ purpose of pointers C++ function pointers c pointer++ why using pointers c++ what is the pointer in cpp pointer cpp function pointers to functions C + + class function pointer cpp pointer to a function cpp C++ allows you to have pointers to pointers to pointers pointer to function c++ pass pointer to function c++ operations with a pointer c++ pointers math program cpp cpp pointers example programs cpp pointers example programa c++ pointer to function function pointer in c++ CPP when to use pointers pointer to pointer in c++ pointer to a function c++ assigning value to pointer to pointer in c++ access pointer to pointer in c++ define pointer in c++ with example is this a pointer in c++ when to use pointers c++ using a pointer c++ create pointer to class c++ this pointer in cpp c++ convert variable to a pointer how to make a value a pointer cpp use of pointers in c++ pointers to pointers c++ what is pointer in c++ with example c++ pointers passing pointer to function c++ POINTER IN CPP is pointers different c++ c++ using pointers c++ pointers ptrnukl using pointers to objects in c++ get pointer to function c++ c++ pointer to pointer pointer to pointer c++ using a pointer of class in cpp what is pointer to pointer c++ when to user pointers c++ how to get pointers to a function in c++ function pointer in cpp pointers c++ &amp; are there pointers to functions in c++ this pointer in c++ pointer to a pointer in cpp pointers cpp ** in cpp cpp pointers declare pointer in c++ get pointer cpp how to use int pointers in c++ pointers in c__ cpp pointer pointer to pointer cpp all about pointers in c++ how to create pointer variable c++ why would you need to use pointers in C++ how to create pointers in c++ what is a pointer in cpp create a pointer to a variable in c++ create a pointer variable in c++ ++ pointers Declare two pointers to integer values. Print the values and address.in C++ pointer to pointer what are c++ pointers used for declare pointer c++ c++ pointers to pointers cpp function pointer += c++ pointer example how to declare a pointer in c++ * in pointers C++ how to increment pointer address c++ make a variable with the name of the pointer its stored at C++ (ptr+i) c++ c++ get pointer of variable put address in pointer c++ how to create a variable with a name of its pointer C++ pointer type variables in c++ set value at pointer c++ A pointer variable in c++ c++ get the value from a pointer imncrement memory address c++ how to make a pointer in cpp c++ get pointer from value pointer declaration c++ pointer types iin c++ create a pointer to an element in c++ c++ pointer after c++ create variable with same memory how to get a pointer c++ how to find the pointer in c++ &amp; pointers get address of variable c++ how to declare a pointer variable c++ how to get the content of a pointer in c++ understanding pointers in c++ c++ get pointer location of variable how to get the int for a pointer to the int C++ c++ &amp; * location get set c++ pointers c++ pointer get value create int pointer pointer c++ definition c++ use elemtns and save pointer int *a c++ access value of a pointer c++ examples of pointers in c++ what are pointers in c++ definition of a pointer c++ what are pointers in cpp What are C++ pointers how to declare a variable as a pointer c++ set pointer c++ c++ pint kom pointers c++ com pointers c++ &amp; in c++ int pointer ++ c++ int pointer c++ how to define a pointer c++ pointer symbols in c++ what defines the value of a pointer c++ pointer cpp pointers c++ explained how to get the value from address of pointer in c++ how to get a variable from a pointer in c++ c++ pointers tutorial c++ set variable with pointer c++ what is a pointer variable c++ variable positions what does it mean how to access a point in c++ how to insert value at a pointer in c++ pointer c++ program c++ get pointer address &amp;*pointer c++ c++ assign value to pointer memory what do your use potiner for in C++ ptr C++ pointers and memory c++ what is a pointer cpp c++ pointer contains -858993460 what can cpp pointers be used for pointer variable c++ c++ pointer variable how do I print all pointers in c++ what is pointer in c++ .* in c++ assign float variable to pointer c++ pointers c++ definition how to get the value of pointer in c++ how to give an address a value with a pointer c++ get value of pointer cpp pointers in c++ explained c++ * how to make in address in c++ store a value c++ set pointer value c++ pointer poiner in c++ c++ what are pointers add variable at certain memory adress c++ location of a pointer C++ c++ what pointer has address cpp pointer c++ syntax how to create a pointer in c++ what is pointers c++ what do we mean by changing pointer type c++ declaring a pointer in c++ pointer in c++ what is a pointer in c++ pointers in c++ pointer c++ read variable from pointer c++ pointers c++ &amp; c++ address to an address c++ pointers in cpp
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source