0% found this document useful (0 votes)
15 views5 pages

Identifiers

The document outlines the rules and best practices for naming identifiers in C++, emphasizing the use of alphanumeric characters, case sensitivity, and avoidance of reserved keywords. It also provides a comprehensive list of C++ operators, including arithmetic, relational, logical, bitwise, assignment, unary, ternary, and other operators, along with their functions. Best practices for naming identifiers include using descriptive names, camel case, and uppercase for constants.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Identifiers

The document outlines the rules and best practices for naming identifiers in C++, emphasizing the use of alphanumeric characters, case sensitivity, and avoidance of reserved keywords. It also provides a comprehensive list of C++ operators, including arithmetic, relational, logical, bitwise, assignment, unary, ternary, and other operators, along with their functions. Best practices for naming identifiers include using descriptive names, camel case, and uppercase for constants.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

C++ Identifiers

Identifiers in C++ are used to identify variables, functions, classes,


objects, arrays, etc. An identifier in C++ must follow certain rules:

Rules for Naming Identifiers


1. Alphanumeric Characters: Identifiers can consist of letters
(both uppercase and lowercase), digits, and underscores (_).
However, it must start with either a letter or an underscore. It
cannot start with a digit.
2. First Character: The first character must be a letter or an
underscore. Identifiers cannot start with a digit.
3. Case Sensitivity: Identifiers are case-sensitive,
meaning Variable and variable are considered different identifiers.
4. Reserved Keywords: Identifiers cannot be keywords or reserved
words in C++. (such as int, float, if, else, while, etc.).
5. Length: Identifiers can be of any length, but it is a good practice to
keep them reasonably short and meaningful.

Examples of Valid Identifiers


Examples of Invalid Identifiers

Best Practices for Naming Identifiers


1. Descriptive Names: Use meaningful and descriptive names that
convey the purpose of the identifier.
2. Camel Case: For variables and functions, use camel case
(e.g., myVariable, calculateSum).
3. Uppercase for Constants: Use uppercase letters for constants
(e.g., MAX_VALUE, PI).
4. Avoid Single Letters: Avoid using single letters except for loop
counters (e.g., i, j)
C++ Operators
Arithmetic Operators
 + : Addition
 - : Subtraction
 * : Multiplication
 / : Division
 % : Modulus
Relational Operators
 == : Equal to
 != : Not equal to
 > : Greater than
 < : Less than
 >= : Greater than or equal to
 <= : Less than or equal to
Logical Operators
 && : Logical AND
 || : Logical OR
 ! : Logical NOT
Bitwise Operators
 & : Bitwise AND
 | : Bitwise OR
 ^ : Bitwise XOR
 ~ : Bitwise NOT
 << : Left shift
 >> : Right shift
Assignment Operators
 = : Assign
 += : Add and assign
 -= : Subtract and assign
 *= : Multiply and assign
 /= : Divide and assign
 %= : Modulus and assign
 &= : Bitwise AND and assign
 |= : Bitwise OR and assign
 ^= : Bitwise XOR and assign
 <<= : Left shift and assign
 >>= : Right shift and assign
Unary Operators
 + : Unary plus
 - : Unary minus
 ++ : Increment
 -- : Decrement
 ! : Logical NOT
 ~ : Bitwise NOT
Ternary Operator
 ?: : Ternary conditional
Other Operators
 sizeof : Returns the size of a variable or type
 & : Address of operator
 * : Pointer dereference
 -> : Member access through pointer
 . : Member access
 , : Comma operator
 :: : Scope resolution
 new : Dynamic memory allocation
 delete : Dynamic memory deallocation
 typeid : Returns the type information
 decltype : Inspects the declared type of an entity
 static_cast : Compile-time cast
 dynamic_cast : Runtime cast (for polymorphic types)
 const_cast : Casts away constness
 reinterpret_cast : Casts between unrelated types

You might also like