我不知道真正的&放大器;一个回报? [英] I wonder what really the &a returns?

查看:182
本文介绍了我不知道真正的&放大器;一个回报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设

第一种情况

  int类型的;
 为int * p =&放大器;一个;它的工作原理没有错误

第二种情况

 长int类型的;
 长整型B:
 B =&安培;一个;它不会工作

我们大多数人说,b是varible不是指针。但看到下面的

所以,问题是,如果和放大器;一个返回这是一个无符号整数,那么为什么不能,我们将其分配给普通变量的地址?但为什么只有指针?
见下文

  B =(unsigned int类型)及一个;它的工作原理虽然类型转换它不是practissable后

如果地址是整数格式,那么为什么不无符号整数或长整数保存。我在想,一定有它背后的一些不可告人的秘密。谁能透露吗?我想是,指针必须在里面做一些事情,但我不知道那会是什么,为什么一个正常的变量不能忽视的。

感谢您的答案,但实际的问题,真正的&放大器;一个回报?整数值或不?如果它是整数为什么一个变量不能持有吗?长整型A = 65535 \\有效,为什么不是int a =和b,如果地址B的值是65535

我不是担心使用它作为指针,请问题是关于刚刚保存的价值。不derefercing地址。有人说32或64位,林并不担心。为什么如果地址是一个整数它不能保存地址?

我的意思是为什么不能我们分配的价值,我不是说指定指针变量的属性只是赋值完蛋了。

  A = 65535
B = A \\\\的作品并将其分配b - 65535
&放大器;一个= 65535
B =&安培;一个\\\\不工作,如果地址是一些整数值,为什么我们不能将其存储在一个变量?

把16位为例正常指针(地址),大小为2个字节,可变大小为什么不能我们存储在其他varibale的ADRESS如果地址是整数这就是我的问题,我发现很多的答案就像​​++这2个字节递增4指针和值1变量,不是,只是将数值担心的是更重要的问题。

  B =放大器;一个 ;的地址是4000
  ++ B:成为4001完蛋了,那不是问题


解决方案

整数,甚至长整型,并不总是将成为大小为指针一样。有时,他们会(例如,大多数32位架构有的sizeof(int)的==的sizeof(无效*)),有时他们会有所不同(例如,一些64位架构有的sizeof(长)==的sizeof(无效*),但有些没有 - 的Visual C ++在Windows上是一个编译器,其中<$ C的典范$ C>的sizeof(长)!= sizeof的(无效*))。

还有一个事实,即无效* 是根本不一样的的键入的如长整型

想象一下,一个类和类酒吧,像这样定义的:

 类Foo {
   市民:int类型的;
};Bar类{
   市民:INT B:
};

这就像问你为什么不能一流的一个实例分配给类型的变量酒吧 - - 他们是不一样的东西,即使在这种情况下,两个酒吧有相同的底层位模式

suppose

First case

 int a;
 int *p= &a ; it works no error

Second case

 long int a;
 long int b;
 b = & a; it wont work 

Most of us say b is a varible not a pointer. But see the below

So the question is if the &a returns the address which is an unsigned integer then why cant we assign it to a normal variable? but why only to pointers ? see below

b = (unsigned int) &a ; it works after typecasting though its not practissable

if the address is integer format then why dont the unsigned or long integers save it . I was thinking, there must be some hidden secret behind it. Could anyone reveal it? What I thought is , pointers must be doing something inside but i wonder what it would be and why a normal variable cant be.

Thanks for all your answers but the actual question what really the &a returns ? integer value or not ? if it is integer number why a variable cannot hold it ? long int a =65535 \valid why not int a= &b if value of address b is 65535

Im not worried to use it as pointer, Please the question is about just saving the value. Not derefercing the address. People saying 32 or 64 bit, Im not worried about that. why it cant save the address if address is a integer number ?

I mean why cant we assign the value, Im not saying to assign the properties of pointers to variable but just assign the value thats it

a=65535
b = a \\ works it assigns b - 65535
&a=65535
b = & a   \\ doesnt work, if address is a some integer value,why we cant store it in a variable?

take the 16 bit as example normal pointer (the address ) size is 2 bytes and variable size is 2 bytes why cant we store the adress in other varibale if address is integer value thats my question i find many answers like ++ it increments by 4 to pointer and value 1 to variable ,not worried about that just assigning the value is more important question.

  b = & a ; address of a is 4000
  ++b ; becomes 4001 thats it,thats not a problem 

解决方案

Integers, even long int, are not always going to be the same size as a pointer. Sometimes they will be (for example, most 32-bit architectures have sizeof(int) == sizeof(void *)), sometimes they will be different (for example, some 64-bit architectures have sizeof(long) == sizeof(void *) but some do not -- Visual C++ on Windows being a prime example of a compiler where sizeof(long) != sizeof(void *)).

There's also the fact that void * is simply not the same type as long int.

Imagine a class Foo and a class Bar, defined like so:

class Foo {
   public: int a;
};

class Bar {
   public: int b;
};

It's like asking why you can't assign an instance of class Foo to a variable of type Bar -- they're not the same thing, even though in this case both Foo and Bar have the same underlying bit pattern.

这篇关于我不知道真正的&放大器;一个回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆