answersLogoWhite

0


Best Answer

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
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

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.

This answer is:
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
Related questions

In c plus plus are local declarations visible to the function in a program?

If you declare a variable inside of any fuction (except main) it will not be available to other functions.


How do you define a symbol such as plus or - as a variable in python?

Use a character variable. For example: plus = '+' minus = '-' You can now refer to these symbols using the variable names "plus" or "minus".


Most c plus plus plus programmers use uppercase letters for variable names?

No.


Which word is reserved in c plus plus?

All C++ keywords are reserved, as are all variable and function names that begin with two leading underscores.


Why you need to declare variable 1st in turbo c plus plus?

In C++ all names (including variables) must be declared before they can be used.


What is the variable of x plus 10 plus 4x-35?

What is the variable of x plus 10 plus 4x-35?


What does a constant do in c plus plus?

A constant is a variable that does not change. The correct term is constant variable.


What is the answer to a variable squared plus ten times a variable plus twenty-four in?

a2/2


What is the variable in this equation 7y plus 10 equals -6 plus 14?

y is the variable


What is a variable plus a variable?

A variable is a named memory location for which the contents are volatile. The antonym of variable is constant.


What is the variable in 7d plus 2?

d is the variable here.


What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};