什么是C ++定义,声明和赋值? [英] What exactly are C++ definitions, declarations and assignments?

查看:253
本文介绍了什么是C ++定义,声明和赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于使用词语define,declare和assign可互换,但这似乎是一些人的犯罪。这是正当的吗?我应该只使用单词declare第一次我分配到一个变量?

I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for the first time I assign to a variable? Or is there more to it than that?

推荐答案

定义和声明是相似的,但赋值是非常不同的。

Define and declare are similar but assign is very different.

这里我声明(或定义)一个变量:

Here I am declaring (or defining) a variable:

int x;

这里我为该变量赋值:

x = 0;

这里我在一个语句中执行:

Here I am doing both in one statement:

int x = 0;

请注意

并非所有语言都支持在一个语句中声明和赋值:

Not all languages support declaration and assignment in one statement:

T-SQL

declare x int;
set x = 0;

有些语言要求在声明时为变量赋值。此要求允许语言的编译器或解释器推断变量的类型:

Some languages require that you assign a value to a variable upon declaration. This requirement allows the compiler or interpreter of the language to infer a type for the variable:

Python

x = 0

这篇关于什么是C ++定义,声明和赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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