C语言中什么是标识符及其规则?
标识符是C编程语言中使用的标记之一。它是一个名称,用于标识变量、常量、函数、数组以及用户定义的数据。
我们不能使用关键字作为标识符,因为关键字是为特殊用途而保留的。一旦声明,我们就可以在后面的程序语句中使用标识符来引用关联的值。
特殊类型的标识符称为语句标签,可以在goto语句中使用。
规则
命名标识符的规则如下-
标识符名称是唯一的。
不能使用关键字作为标识符。
标识符必须以字母或下划线(_)开头。
它不应包含空格。
不允许有特殊字符。
标识符只能由字母、数字或下划线组成。
只有31个字符是有意义的。
它们区分大小写。
示例
以下是用于识别哪些术语被称为标识符的C程序-
/* C Program to Count Vowels and Consonants in a String */ #include输出结果int main(){ char str[100]; int i, vowels, consonants; i = vowels = consonants = 0; printf("\nEnter any String : "); gets(str); while (str[i] != '\0'){ if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U'){ vowels++; } else consonants++; i++; } printf("\n no of Vowels in the given String = %d", vowels); printf("\n no of Consonants in the given String = %d", consonants); return 0; }
执行上述程序时,会产生以下结果-
Enter any String : nhooo.com no of Vowels in the given String = 6 no of Consonants in the given String = 9
在上面的程序中,标识符是-
Str,i,元音,辅音
热门推荐
10 乔迁祝福语简短精辟句子
11 霸气新年祝福语大全简短
12 送给妈妈新年祝福语简短
13 晚安好梦祝福语简短
14 蛋糕祝福语简短给老婆
15 2026腊八简短祝福语
16 预祝中秋简短的祝福语
17 元旦感恩祝福语简短大全
18 平安果祝福语简短霸气