#include <stdio.h>
int main(int argc, const char * argv[]) {
int *pi = NULL;
void *voidptr = pi;
int num = 100;
pi = #
printf("%p\n",pi);
printf("%p\n", voidptr);
return 0;
}
为什么第二个printf会给出0x0但地址不同于第一个?
答案 0 :(得分:2)
由于对一个对象的分配不会影响C中的另一个对象,因此voidptr
pi
的值为NULL
,因此printf()
尚未更新。分配给它。
顺便提一下,您通过将具有错误类型的数据传递给int*
来调用未定义的行为:您通过%p
而void*
期望public class Form1 {
public Form1() {
InitializeComponent();
}
// SomeButton is Clicked
public void SomeButton_Click(object sender, EventArgs e) {
// SomeButton is disabled
SomeButton.Enabled = false;
// Form2 is created
var form2 = new Form2();
// Subscribing to Form2's Closed event
form2.Closed += OnClosed;
}
private void OnClosed(object sender, EventArgs eventArgs)
{
// Event is fired and you can enable the button
SomeButton.Enabled = true;
}
}