Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'default' as a variable name

Tags:

c++

keyword

names

While debugging some code, I came across an array named default. I thought that keywords were not allowed as variable names.

#include "stdafx.h"
#include <stdio.h>

int main()
{
 int default = 5;
 printf("%d\n", default);
 return 0;
}

Now the above code compiles without a hitch on VS 2008. Isn't 'default' a keyword? How come it works as a variable name? Side-effects?

PS: Infragistics::Win::UltraWinToolbars::ToolbarsCollection has a property with this name!

like image 420
Agnel Kurian Avatar asked Mar 19 '09 21:03

Agnel Kurian


People also ask

Can we use default as variable name in Java?

In Java, Using predefined class name as Class or Variable name is allowed.

How do you write a variable name?

A variable name must start with a letter or an underscore character (_) A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables)

What should variable names start with?

By Convention: Variable names begin with a lowercase letter, and class names begin with an uppercase letter. If a variable name consists of more than one word, the words are joined together, and each word after the first begins with an uppercase letter, like this: isVisible .

What variable name means?

A Variable name is used to refer to a variable (column of the data matrix) for all commands dealing with data in SPSS. The following rules apply when creating new variables or changing the name of an existing variable: Variable names must be unique in a Dataset.


1 Answers

It's a known issue in VC++. Basically by-design for C++/CLI compatibility.

like image 72
Neil Williams Avatar answered Nov 13 '22 17:11

Neil Williams