English 中文(简体)
1. 在加固点时有或没有星号
原标题:With or without an asterisk when incrementing pointer

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;
}

接受解决办法后的最新情况 我试图根据“Cody Gray”的回答,澄清我得到的东西。 <代码>pchar的地址已加起来,以指明非专利地点。 但是,由于<代码>a 载于main,而不是pchar, 即<编码>。 仍然印刷了某种意义的价值(例如是x)。

最佳回答

www.un.org/spanish/ecosoc 页: 1

因此,该法典:

++(*pint)

<>t>pint。

相比之下,该法典:

++(pint)

插入pointer se,pint。 这就是为什么点人指出的价值没有变化。 你不改变点人指出的价值,而是点人本身的价值。

点名的 Inc缩将使它在记忆中显示出完全不同的价值。 在此情况下,由于你只分配了用于单一分类的面积,这将表明非专利价值。

问题回答

当你从点子到其他点子时

char* pchar;
pchar = (char*) data;

你告诉汇编者,把这一记忆作为果点处理,你可以对这一变数进行点算。 因此,你与点人不合作,这是你正在做算术的记忆。

• 发挥你所需要的价值,使用“*”或用斜体接触记忆点。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签