int *p = &a 和 q = &a 有什么区别 [英] What's the difference between int *p = &a and q = &a
本文介绍了int *p = &a 和 q = &a 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
学习者问题.我可以用两种不同的方式声明和初始化一个指针
Learner question. I can declare and initialize a pointer in two different way
int a = 10;
int *p = &a;
还有
int a = 10;
int *q;
q = &a;
我想知道两者有什么区别,在内存中是如何工作的?
I want to know what is the difference between two and how does it work in the memory?
推荐答案
这两个是一样的 :
int *p; // declaration
p = &a; // assignment
另一方面,您将两个步骤合二为一:
and in the other you are combining the two steps together into one:
int *p=&a; // declaration and assignment
如果您开启了一些编译器优化,编译器可能会将这两个步骤结合起来.
And if you have some compiler optimizations ON, the compiler might combine the two steps.
这篇关于int *p = &a 和 q = &a 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文