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

  • SEARCH
  • Home
  • 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 7940033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:16:01+00:00 2026-06-03T23:16:01+00:00

In void pointers example in the tutorial on cplusplus.com , I try to compare

  • 0

In “void pointers” example in the tutorial on cplusplus.com, I try to compare like following. Why do we still need * in parenthesis? What is happening when no *?

void increase(void* data, int psize) {
    if (psize == sizeof(char)) {
        char* pchar;
        pchar = (char*) data;
        cout << "pchar=" << pchar << endl;
        cout << "*pchar=" << *pchar << endl;
        //++(*pchar);   // increases the value pointed to, as expected
        ++(pchar);      // the value pointed to doesn't change 
    } else if (psize == sizeof(int)) {
        int* pint;
        pint = (int*) data;
        //++(*pint);   // increases the value pointed to, as expected
        ++(pint);      // the value pointed to doesn't change 
    }
}

int main() {
    char a = 'x';
    int b = 1602;
    increase(&a, sizeof(a));
    increase(&b, sizeof(b));
    cout << a << ", " << b << endl;
    return 0;
}

Update after accepting solution) I try to make clear what I didn’t get, based on @Cody Gray’s answer. The address of pchar is incremented to point to nonsense location. But because variable a in main is coutted instead of pchar, this cout still prints a value that somewhat makes sense (in this example it would be ‘x’).

  • 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-06-03T23:16:03+00:00Added an answer on June 3, 2026 at 11:16 pm

    The * operator dereferences the pointer.

    Therefore, this code:

    ++(*pint)
    

    increments the value pointed to by pint.

    By contrast, this code:

    ++(pint)
    

    increments the pointer itself, pint. This is why the value pointed to by the pointer doesn’t change. You’re not changing the value pointed to by the pointer, but rather the value of the pointer itself.

    Incrementing a pointer will cause it to point to an entirely different value in memory. In this case, since you only allocated space for a single integer, it will point to a nonsense value.

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

Sidebar

Related Questions

Can someone please explain why pointers aren't initialized to NULL ? Example: void test(){
How do smart pointers handle arrays? For example, void function() { std::unique_ptr<int> my_array(new int[5]);
Take the following example: class BookManager { ... }; class Book { public: void
I have function that receives an array of pointers like so: void foo(int *ptrs[],
I am studying pointers and I encountered this program: #include <stdio.h> void swap(int *,int
Say a function takes a void pointer as an argument, like so: int func(void
The following C++ Win32 console program assigns an array to a pointer to void,
I am looking at the iPhone aurioTouch example specifically on the following code: static
here is example how Pointers are used to store and manage the addresses of
In the following example c code, used in an Arduino project, I am looking

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.