左值必须是一元``&''操作数 [英] lvalue required as unary ‘&’ operand

查看:79
本文介绍了左值必须是一元``&''操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几行代码:

#define PORT 9987

char *ptr = (char *)&PORT;

这似乎可以在我的服务器代码中使用.但是,正如我在客户端代码中所写的那样,它给出了以下错误消息:

This seems to work in my server code. But as I wrote it in my client code, it gives this error message :

lvalue required as unary ‘&’ operand

我在做什么错了?

推荐答案

C预处理程序在这里起作用.在对代码进行预处理之后,它看起来是这样的.

C preprocessor is at play here. After the code is preprocessed, this how it looks like.

char *ptr = (char *)&9987;

(&)运算符的

地址可以应用于变量,而不是文字.

address of (&) operator can be applied to a variable and not a literal.

这篇关于左值必须是一元``&''操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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