简体   繁体   English

int variable_name(0); 是什么? 意思是?

[英]What does int variable_name(0); mean?

I'm learning C in school and could not find any anything about this line of code我在学校学习 C 并且找不到任何关于这行代码的任何信息

int numLetter(0);

We are currently learning about pointers.我们目前正在学习指针。 This line does not show up until the end of a for loop where we add 1 every time a case was satisfied.这条线直到 for 循环结束时才会出现,每次满足条件时我们都加 1。

++numLetter;

Going back to my question on the title.回到我关于标题的问题。 What does int variable(0); int variable(0); 是什么? mean?意思是? Is it the same as initializing a variable like是否与初始化变量一样

int numLetter = 0;

EDIT: Thank you for the response.编辑:感谢您的回复。 In the example I was given we are trying to do pointer arithmetic.在给我的示例中,我们正在尝试进行指针运算。 The sample code is below:示例代码如下:

const size_t arr_len = 7;
char name[arr_len] = "Marzian";
int numVow(0);

for (char *ptr = name; ptr < name + arr_len; ++ptr) 
{
    switch (*ptr)
    {
        case "A":
        case "a":
        case "E":
        case "e":
        case "I":
        case "i":
        case "O":
        case "o":
        case "U":
        case "u":
            +++numVow;
    }
}

I thought int numLetter(0);我以为 int numLetter(0); has something to do with pointer syntax.与指针语法有关。 But like you guys have mentioned it is not a valid C syntax.但是就像你们提到的那样,它不是有效的 C 语法。 My professor might have just mixed up the syntax when he made this example.我的教授在做这个例子时可能只是混淆了语法。 While I am here.当我在这里时。 Do you guys have any resources to understand pointer a lot better?你们有任何资源可以更好地理解指针吗? Im not used to pointer/address I never used something similar when I was practicing python.我不习惯指针/地址我在练习 python 时从未使用过类似的东西。

Thanks everyone for the help!感谢大家的帮助!

This isn't a valid syntax in C language.这不是 C 语言中的有效语法。

But in C++, The value is being initialized to zero in the syntax given.但是在 C++ 中,该值在给定的语法中被初始化为零。 You could say that:你可以那样说:

int x(0);
int y = 0;

Both of the aforementioned statements are valid and equivalent to each other and they've nothing related to the pointers.上述两个语句都是有效的并且彼此等效,并且它们与指针没有任何关系。

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

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