Answers for "pointer object in c++"

C++
2

pointer c++

int myvar = 6;
int pointer = &myvar; // adress of myvar
int value = *pointer; // the value the pointer points to: 6
Posted by: Guest on September-12-2021
2

pointer in c++

// Variable is used to store value
int a = 5;
cout << a; //output is 5

// Pointer is used to store address of variable
int a = 5;
int *ab;
ab = &a; //& is used get address of the variable
cout << ab; // Output is address of variable
Posted by: Guest on May-27-2021
0

c++ pointer

#include <iostream>

void pointers_with_dynamic_memory() {
	int  arr_size;   // arr_size can contain an integer
    int* x;          // x can contain the memory address of an integer.
    
    std::cout << "enter an integer > 0: ";
  	std::cin >> arr_size; 
    
    // value of x is the starting address of a heap-allocated block ints	
    x        = new int[arr_size];  
  
  	x[0]     = 10;  // set first element of array to 10
    *x       = 50;  // set first element of array to 50
    *(x + 1) = 100; // +1 offsets automatically by the value of sizeof(int)
  
    delete [] x;
}
Posted by: Guest on July-10-2021
0

pointers c++

// pointer to functions
#include <iostream>
using namespace std;

int addition (int a, int b)
{ return (a+b); }

int subtraction (int a, int b)
{ return (a-b); }

int operation (int x, int y, int (*functocall)(int,int))
{
  int g;
  g = (*functocall)(x,y);
  return (g);
}

int main ()
{
  int m,n;
  int (*minus)(int,int) = subtraction;

  m = operation (7, 5, addition);
  n = operation (20, m, minus);
  cout <<n;
  return 0;
}
Posted by: Guest on June-15-2021
2

what is this pointer in c++

Every object in C++ has access to its own address through an important pointer called this pointer.
 The this pointer is an implicit parameter to all member functions. 
Therefore, inside a member function,
 this may be used to refer to the invoking object.

Friend functions do not have a this pointer,
 because friends are not members of a class. 
Only member functions have a this pointer.
Posted by: Guest on May-14-2021
0

pointer in c++

int* pointVar, var;
var = 5;

// assign address of var to pointVar
pointVar = &var;

// access value pointed by pointVar
cout << *pointVar << endl;   // Output: 5

In the above code, the address of var is assigned to the pointVar pointer.
We have used the *pointVar to get the value stored in that address.
Posted by: Guest on September-09-2020

Browse Popular Code Answers by Language