简体   繁体   English

c语言中字符串名和字符串名()的区别

[英]difference between string name and string name() in c language

I have a hard time understanding what is the difference between我很难理解这之间有什么区别

 string name;

and

 string name();

Could someone explain me the difference?有人可以解释我的区别吗?

Assuming string is a data type you have already declared, string name;假设string是您已经声明的数据类型, string name; declares the variable name of type string .声明类型为string变量name

The declaration string name();声明string name(); declares the function name that returns a value of type string .声明返回string类型值的函数name

A variable is a place in memory where the program can store some data.变量是内存中程序可以存储一些数据的地方。 A function is a piece of code that can be executed multiple times, when needed;函数是一段可以在需要时执行多次的代码; it can receive (zero or more) arguments and it can optionally return one value.它可以接收(零个或多个)参数,并且可以选择返回一个值。

string name;字符串名称; Declare the string data type variable 'name' in a memory where as string name();在内存中声明字符串数据类型变量“名称”,其中为字符串名称(); shows the function prototype named as 'name' which returns the string value.显示名为“name”的函数原型,它返回字符串值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM