pointer in cpp details

Solutions on MaxInterview for pointer in cpp details by the best coders in the world

showing results for - "pointer in cpp details"
Ben
01 Jan 2021
1Every object in C++ has access to its own address through an important pointer called this pointer.
2 The this pointer is an implicit parameter to all member functions. 
3Therefore, inside a member function,
4 this may be used to refer to the invoking object.
5
6Friend functions do not have a this pointer,
7 because friends are not members of a class. 
8Only member functions have a this pointer.
Valerio
06 May 2020
1#include <iostream>
2using std::cout;
3
4int main() {
5  /* 
6  Some things to keep in mind:
7  	-you shouldn't circumvent the type system if you are creating raw ptrs
8  	and don't need to "type pun" or cast (don't use void ptrs)
9    -ptr types only reference memory (which are integers), not actual data, thus
10    they should not be treated as data types
11    char* is just 1 byte of mem, int* is just 4 bytes of mem, etc
12    - '*' means that you are creating a pointer which "points" to the mem address
13    of a variable
14    - '&', in this case, means "get the mem address of this variable"
15  */
16  
17  void* ptr; // a pointer that doesn't reference a certain size of memory
18  int* int_ptr; // a pointer that points to data with
19  				// only 4 bytes of memory (on stack)
20  
21  int a = 5; // allocates 4 bytes of mem and stores "5" there (as a primitive)
22  ptr = &a; // can only access the memory address of 'a' (not the data there)
23  
24  int b = 45; 
25  int_ptr = &b; // can access both memory address and data of 'b'
26  
27  cout << ptr << "\n"; // prints mem address of 'a'
28  /*cout << *ptr << "\n"; <- this will error out; a void ptr cannot be 
29  							 derefrenced */
30  cout << *(int*)ptr << "\n"; // type punning to get around void ptr (extra work)
31  
32  cout << int_ptr << "\n"; // mem address of b
33  cout << *int_ptr << "\n"; // data stored at b
34  
35  /* -- OUTPUTS -- */
36  /*
37  	some memory address (arbitrary) which contains 05 00 00 00 as its data
38  	5
39    some memory address (arbitrary) which contains 2D 00 00 00 as its data
40    45
41  */
42  
43  return 0; // you only need this if "main" isnt the linker entry point
44  			// you also don't care
45  
46  // ur also probably wondering why I didn't using namespace std... cherno
47}
Isabel
27 Aug 2020
1#include <iostream>
2using namespace std;
3class Demo {
4private:
5  int num;
6  char ch;
7public:
8  void setMyValues(int num, char ch){
9    this->num =num;
10    this->ch=ch;
11  }
12  void displayMyValues(){
13    cout<<num<<endl;
14    cout<<ch;
15  }
16};
17int main(){
18  Demo obj;
19  obj.setMyValues(100, 'A');
20  obj.displayMyValues();
21  return 0;
22}
queries leading to this page
26 c 2b 2bc 2b 2b pointersc 2b 2b pointers explainedpointers in c set pointer c 2b 2bhow to find the pointer in c 2b 2bcpp function pointer typehow to make a value a pointer cpphow to create pointer variable c 2b 2bc 2b 2b value of pointerusing this 3e pointer in c 2b 2buses of pointers in c 2b 2bc 2b 2b pointer variablewhat does pointers do in c 2b 2breference and pointer in function c 2b 2bpointer of class type in cpppointers c 2b 2b explainedc 2b 2b pointer class functionget address of variable c 2b 2bget set c 2b 2b pointerspointer declaration in c 2b 2bcom pointers c 2b 2bpointer to a function cpppointer declaration example in c 2b 2bhow to create pointers in c 2b 2bc 2b 2b pointers exampleswhy to use pointers in c 2b 2bshould you use pointers in c 2b 2bpointer in c 2b 2b examplecreate a function pointer c 2b 2bcreate a pointer to an element in c 2b 2bpointer example in c 2b 2bwhat 27s the point of a pointer in c 2b 2bpointers in c 2bc 2b 2b define pointer locationpointer in c 2b 2b definitionclass pointer in c 2b 2bc 2b 2b get pointer of variableclass pointer c 2b 2bcpp declare a pointerpointers in classic c 2b 2busing pointers through functions c 2b 2b 26 in c 2b 2bdoes c 2b 2b have pointersset value at pointer c 2b 2bput address in pointer c 2b 2bc 2b 2b function pointers 26pointer in cpppointers c 2b 2b in detailshow do i print all pointers in c 2b 2bwhen use pointers in c 2b 2bobject and pointer in c 2b 2bc 2b 2b using pointerswhat are pointers in cpppointers questions in cpppointer function ni cppc 2b 2b declare pointercreate a pointer cppuse of 27this 27 pointer in classe in c 2b 2busing a pointer c 2b 2bpointer to function in cppc 2b 2b set variable with pointerexplain pointers and objects in c 2b 2b with examplecpp class function pointerpointer concept in cpp 5ccreate a pointer variable in c 2b 2bc 2b 2b pointer in cpointer symbols in c 2b 2b 26 c 2b 2b 3d meaning pointerspointer definition in cpppointers in cppreference a pointer c 2b 2bcpp pointer applicationsuse of function pointer in c 2b 2bdeclare pointer in c 2b 2bc 2b 2b get pointer from valuepointer declaration c 2b 2bwhat happens if you use pointer for function c 2b 2bc 2b 2b are references pointerspointer in cppare there pointers to functions in c 2b 2bpointer variable c 2b 2bobject pointer in c 2b 2btypes of pointers in cppcpp make a pointer to a pointerusing pointers in functions c 2b 2bc 2b 2b how to store pointersstates of a pointer in c 2b 2bhow to create a pointer in c 2b 2bthis pointer use in c 2b 2bwhat is 26 in c 2b 2b pointerswhat is a pointer in c 2b 2bhow to declare a pointer c 2b 2bhow to get the pointer for a variable in c 2b 2bclass function pointer cppwhat are c 2b 2b pointerspointer c 2b 2b definitionworking with pointers in c 2b 2bcalling a pointer function in c 2b 2bc 2b 2b why do we use pointerscpp function pointerc 2b 2b 26 2a locationc 2b 2b what does a pointer containpointers math program cppwhat defines the value of a pointer c 2b 2bwhy use pointer to pointer in c 2b 2bpointers c 2b 2bwhat are pointers in c 2b 2b 2bwhat are pointers used for in c 2b 2bc 2b 2b pointers to functionswhat is the point of using pointers in c 2b 2bfunction of pointer c 2b 2bassign float variable to pointer c 2b 2bhow to create a variable with a name of its pointer c 2b 2bc 2b 2b pointer to pointer classc 2b 2b pointer contains 858993460what can cpp pointers be used forc 2b 2b what are pointersc 2b 2b create pointer to functionc 2b 2b set pointer positiondoes c 2b 2b have pointershow do pointers work in c 2b 2bwhen to user pointers c 2b 2bcpp pointerget pointer of variable c 2b 2bpointer pointer variable in c 2b 2breference and pointer in c 2b 2bhow often are pointers actually used in c 2b 2bwhat is this pointer in c 2b 2bdifferent types of pointers in cpptype of pointers in c 2b 2bpointer function c 2b 2bwhy would you need to use pointers in c 2b 2bpointer and functions with example in c 2b 2bc 2b 2b how to work with pointer in functionc 2b 2b pinta pointer variable in c 2b 2bint pointer 2b 2b c 2b 2bhow to declare a pointer in c 2b 2bc 2b 2b create variable with same memorycpp 2a on pointerhow to declare pointer in c 2b 2b 2bclass and pointers in c 2b 2bdeclaring a pointer in c 2b 2bdeclare a function pointer c 2b 2bwhy would you use pointers in c 2b 2b 26 pointersc 2b 2b what is this pointerpointer and new in cppdefinition of a pointer c 2b 2bcreate a structure pointer c 2b 2bwhat is the use of 26 in pointers in c 2b 2bhow to give an address a value with a pointer c 2b 2bc 2b 2b how to have cirkular pointerspointer in cpp detailsclass name as pointer in c 2b 2bsignificance of this pointer in c 2b 2bpointer of structure in c 2b 2bwhat are pointers in c 2b 2bwhat is the e2 80 9cthis e2 80 9d pointer in c 2b 2b 3f explain c 2b 2b why are pointers usefulfunction pointer cpppointer and function in c 2b 2bhow to make a pointer in cppfunction pointer in cpphow to put pointers in c 2b 2bwhat is the 22this 22 pointer in c 2b 2b 2c and what purpose does it servewhat is the use of pointers in c 2b 2b 3fc 2b 2b pointer in function pathis pointer in cppc 2b 2b function pointer to pointerc 2b 2b class pointerhow to declare a pointer variable c 2b 2bpointers inc 2b 2bthis pointer in c 2b 2bfunction pointers in cpphow to get the content of a pointer in c 2b 2bclass pointers in p 5dcpppointer type variables in c 2b 2busing with pointer c 2b 2bc 2b 2b pointerwhy using pointers c 2b 2bwhat is class pointer in c 2b 2bwhy use pointers to pointers c 2b 2bpointer function in c 2b 2bc 2b 2b where does the 2a pointershow to use int pointers in c 2b 2bthis pointer in c 2b 2b with examplepointers and types of pointers in cpphow to take ina pointer c 2b 2bread variable from pointer c 2b 2bthis pointers c 2b 2b pointers to pointers in cppuses of this pointer in c 2b 2b 22pointer function 22 c 2b 2bint 2aa c 2b 2bfunction pointer in c 2b 2bc 2b 2b pointer operationshow do pointers work in cpppointers in class in c 2b 2bshould i use pointers in c 2b 2bpointers explained c 2b 2boperations on pointers c 2b 2bpointers constructor in c 2b 2bis pointers different c 2b 2bget value of pointer cppfunction pointer to c 2b 2bwhat is pointers c 2b 2bc 2b 2b what pointer hasusing a pointer of class in cpppointer to pointer in c 2b 2bwhat is pointer in cppwhy use pointers in c 2b 2blocation of a pointer c 2b 2bpointer operations in cpppointers c 2b 2b definitionwhen to use pointers c 2b 2b 2a in c 2b 2bpointer and function in cppcpp pointers example programathis pointer in c 2b 2bwhy are pointers useful in c 2b 2bexamples of pointers in c 2b 2bc 2b 2b reference pointeris this a pointer in c 2b 2bc 2b 2b why use pointersimncrement memory address c 2b 2btype of this pointer in c 2b 2bwhy we use pointers in cpphow to increment pointer address c 2b 2bwrite a program to implement pointers in c 2b 2bpointer example in cpp 2a pointers cppwhat are pointers in c 2b 2b pointer cppcpp pointer declarationuse of 27this 27 pointer in class in c 2b 2bwhat is the use of pointers in c 2b 2bcpp pointer to pointer newwhat are c 2b 2b pointers used forusing 21 21 with pointer c 2b 2bdeclare pointer as pointer in cpphow to access a point in c 2b 2bcreate int pointerpointer class in c 2b 2bwhat is c 2b 2b pointerspointer c 2b 2b programhow to create pointer object in c 2b 2bc 2b 2b get the value from a pointerc 2b 2b pointers in functionshow to declare and use pointers c 2b 2bdoes c 2b 2b language have pointersreference pointer in c 2b 2bc 2b 2b 2awhy do we need pointers in c 2b 2bhow to declare a variable as a pointer c 2b 2busage of pointers in c 2b 2bc 2b 2b function pointerwhat 27s the point of pointers c 2b 2bare pointers required in c 2b 2bwe are variable then why use pointer in c 2b 2bthis pointer in c 2b 2b exampleclass with pointers cppreference of a pointer c 2b 2bpointer value of c 2b 2b 2b 2b pointersc 2b 2b use elemtns and save pointerpointer object in c 2b 2b 22this 22 pointer c 2b 2bc 2b 2b define pointer to functionint pointer c 2b 2bfunction pointer c 2b 2bhow to use pointer methodin class in cppc 2b 2b pointer referencefunction pointer syntax c 2b 2ball about pointers in c 2b 2bpoiner in c 2b 2bdeclare pointer c 2b 2bwhat do your use potiner for in c 2b 2bpointer to function c 2b 2bpointer types iin c 2b 2bfunction 22 pointer c 2b 2bpointers and functions c 2b 2bcpp pointersc 2b 2b pointer function in classc 2b 2b how to declare pointer to functiondefine pointer in c 2b 2b with examplec 2b 2b function that takes pointercpp pointers example programsc 2b 2b pointer to pointerwhat can a pointer do cppc 2b 2b variable positions what does it meanwhy pointer to pointer in c 2b 2bkom pointers c 2b 2bwhy use pointers n c 2b 2bwhat is pointer to pointer c 2b 2baddress to an address c 2b 2bhow to create structure pointer in cppc 2b 2b what is the point of pointersc 2b 2b pointer declaration syntaxpointer type in cpp 26 2apointer c 2b 2bwhat is the point of pointers inc c 2b 2bc 2b 2b assign value to pointer memorywhat is pointer in c 2b 2bc 2b 2b pointers and functionswhat is pointer in c 2b 2b with examplehow to use pointers in c 2b 2bwhat is the 22this 22 pointer in c 2b 2b 2c and what purpose does it serve 3fadd variable at certain memory adress c 2b 2bc 2b 2b allows you to have pointers to pointers to pointersvalue of pointer c 2b 2b 22function 22 pointer c 2b 2bc 2b 2b get pointer addresspointers in c 2b 2b explainedunderstanding pointers in c 2b 2bhow to create a pointer to a class in c 2b 2bc 2b 2b when to use pointersc 2b 2b set pointer valuecpp function pointer definehow to implement pointers in c 2b 2b newpointers c 2b 2b 26c 2b 2b pointer examplepointer c 2b 2bget pointer cppfunction pointer example in cppfunction pointers c 2b 2bhow to get the int for a pointer to the int c 2b 2bpointer to pointer c 2b 2bpointer variable in c 2b 2b with examplec 2b 2b pointers ptrnuklptr c 2b 2bthis pointer in class c 2b 2bc 2b 2b have pointersc 2b 2b purpose of pointersmake a variable with the name of the pointer its stored at c 2b 2bhow to use pointer function in class i cpphow this pointer can be used in c 2b 2b explain with example program this pointer c 2b 2bhow to get a pointer c 2b 2bpointer in c 2b 2bset pointer cppc 2b 2b pointer to pointer to pointer access value of a pointer c 2b 2bc 2b 2b get pointer location of variablepointer in class c 2b 2bc 2b 2b pointer aftercreate a pointer to a variable in c 2b 2bpointer reference in c 2b 2bpointer to function in c 2b 2bc 2b 2b in pointer declarepointers cpppointers in c 2b 2bwhat do we mean by changing pointer type c 2b 2bcpp function pointer 2b 3dhow to get a variable from a pointer in c 2b 2bc 2b 2b pointers tutorialhow to insert value at a pointer in c 2b 2boperations with a pointer c 2b 2bthis pointer c 2b 2b explainedpointer to pointer in cppvalue of a pointer in c 2b 2b 2a in pointers c 2b 2buse of new in declaring pointers c 2b 2bcan i create a class pointer in cpppointers and memory c 2b 2beverything you need to know about pointers in c 2b 2bpointer c 2b 2b syntaxwhat must we include to use pointers cpphow to get the value from address of pointer in c 2b 2bpointer cpp functionwhy we use pointers in c 2b 2bcreating pointer to a class in c 2b 2bpointers and addresses cppc 2b 2b what is a pointer variablewhat is a pointer cpp 26 c 2b 2b meaning pointerscpp pointer syntaxwhy use pointers in cppwhat are pointers for c 2b 2baddress cppfunction pointers in c 2b 2busing pointers c 2b 2b exampleshow to make in address in c 2b 2b store a valuepointer in c 2b 2b operatorsaccess pointer value c 2b 2bc 2b 2b pointer declarationc 2b 2b pointer get valuepointers and addresses in cppc 2b 2b set cursor positionbenefits of using pointers in c 2b 2bhow to use pointers in classes in c 2b 2buse of 22this 22 pointer in c 2b 2baccess pointer to pointer in c 2b 2bc 2b 2b pointer functionwhy should i use pointers in c 2b 2bhow to define a pointer c 2b 2bsimple pointer program using c 2b 2bhow to get the value of pointer in c 2b 2bc pointer 2b 2bintro to pointers c 2b 2bwhat is a pointer variable c 2b 2b and how to create oneis c 2b 2b pointers 28ptr 2bi 29 c 2b 2bpointer operations in c 2b 2bpointer in cpp details