Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:38:42+00:00 2026-05-14T14:38:42+00:00

I am trying to write a function that takes a pointer argument, modifies what

  • 0

I am trying to write a function that takes a pointer argument, modifies what the pointer points to, and then returns the destination of the pointer as a reference.
I am getting the following error: cannot convert int*** to int* in return

Code:

#include <iostream>
using namespace std;

int* increment(int** i) {
    i++; 
    return &i;
}

int main() {
    int a=24;
    int *p=&a;
    int *p2;
    p2=increment(&p);
    cout<<p2;
}

Thanks for helping!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:38:42+00:00Added an answer on May 14, 2026 at 2:38 pm

    If you indeed mean “return the destination of the pointer as a reference”, then I think the return type you’re after is int& rather than int*.

    This can be one of the confusing things about C++, since & and * have different meanings depending on where you use them. & is “Reference type” if you’re talking about a variable definition or return type; but it means “Address of” if it’s in front of a variable being used after it’s defined.

    I could be completely mistaken, but it seems to me that you’ve gotten these two meanings mixed up; and since you want to return a reference, you’ve written “return &i“, since & is used for references. However, in this case, it returns the address of i. And since i is a pointer to a pointer to an int, in this line of code:

    int* increment(int** i) { i++; return &i;}
    

    you are returning the address of a pointer to a pointer to an int. That is why you are getting your error message cannot convert int***' to int*.

    Let’s walk through your code line by line. You are after a program that takes a pointer and returns a reference. So that would be:

    int& increment(int* i)
    

    We don’t need the double pointer that you had in your code (unless you want a pointer to a pointer). Then you want it to modify what the pointer points to:

    (*i)++;
    

    And then return the destination of the pointer as a reference:

    return *i;
    

    Here, we are dereferencing i. Remember that using references lets you treat them like normal variables, and handles the pointer stuff for you. So C++ will figure out that you want it to be a reference.

    Then, to use your code, you can do pretty much what you had, but using less pointers:

    int a=24;
    int *p=&a;
    int *p2;
    p2 = increment(p);
    

    I haven’t tested any of this, so anyone may feel free to edit my answer and fix it if I’ve got something wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 410k
  • Answers 410k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would check first whether this hasn't got any CI… May 15, 2026 at 7:25 am
  • Editorial Team
    Editorial Team added an answer I would look at using an interface that they both… May 15, 2026 at 7:25 am
  • Editorial Team
    Editorial Team added an answer An alternative to Comet/Bayeux that has proven to be working… May 15, 2026 at 7:25 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.