answersLogoWhite

0

Any name that is not a reserved word can be a legal variable, function or type name. All names must be alphanumeric, but they cannot begin with a digit. The C++ standard recommends that all user-defined names be written entirely in lower case with underscores for spaces. Some programmers prefer 'camel case' (such as PrintObject and MaxNumber), which was a popular convention amongst the Pascal programming community, however print_object and max_number are the C++ conventions. Names in all caps are typically reserved for macro definitions (which is effectively a separate language from C++ itself), while names with leading underscores should generally be avoided as this convention is utilised extensively within the standard library.

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

JudyJudy
Simplicity is my specialty.
Chat with Judy
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

A variable declaration is where you declare a data type, the name of the data type (so you can refer to it) and an optional initial value for the data type. E.g., the following declares a variable of type int, names it answer, and initialises it with the value 42:

int answer = 42;

The end result is that some memory is allocated to store the int, and that memory is initialised with the value 42. There is no need to know the address of the memory since you can refer to it by the name, answer. But if you should ever need the actual address, the address-of operator will reveal it: &answer.

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What are legal variable names and declarations in c and c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp