C++ Identifiers and constants

C++ Identifier and constant

Identifiers refers to the name of variables, functions, array, classes etc created by The programmer. They are the fundamental requirement of any language. Each language has its own rules for the naming these identifiers.

The following rules are common to both c and the c++

1. The name cannot be start with a digit.
2. only alphabet character, digits and underscore are permitted.
3. Uppercase and lowercase letters are distinct.
4. A declare keyword cannot be used as a varibale name.

Some valid Identifiers examples are

number Amount_pay reg1 _data AVERAGE

Some Invalid Identifiers examples are-

6number int reg# 4data AVERAGE no

auto else new switch
operator temple break enum
private this case extern
throws catch float public
try char for register
typedef class typedef friend
return union const goto
short unsigned continue if
signed virtual default inline
sizeof int delete static
volatile do long struct

Numeric Constant in C++

The Numeric constant consist of numerical digits. They may be without decimal point or may have decimal point(.). These are number of rules for defining numeric constants-

1. Numeric constant should have at least one digit.
2.There should be no comma or space is allow within the numeric constant for defining.
3. Numeric constant may be positive or negative but default sign of numeric constant is always be positive.

Integers Constant in C++

There are three types of integer constant based on numbers systems such (decimal, octal, hexadecimal) so here all are integer constants or integer types constants but based on number system

Decimal constants- 0,1,2,3,4,5,6,7,8,9 (base 10)
octal constants- 0,1,2,3,4,5,6,7 (base 8)
Hexadecimal constants 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f (base 16)

lets us see some valid decimal integers constants are-

0 156 8765 3459 66558

here are some invalid decimal integers constants are in the below example-

Invalid

Remarks

8.5

illegal character(.)

67 9

No black space allowed

86,55

comma not allowed

05546

first digit can not be zero

809#55

Illegal character (#)

let us see some valid octal integers constants and take example, first digit must be 0.

0 0156 0765 08 0558

let us see and take example of some valid Hexadecimal integers constant, first two characters should be 0X or 0x. some examples are

0X89 0x6653 0X98FBC 0xAAABM 0Xabm

Real(Floating point) Constant in C++

The Floating point constant are numeric number constant with decimal point. Here take example of some floating point constants –

0.9 3.459 6655.8 100.6 5.2 99.33

Character Constant in C++

The character constant is the single character that is enclosed with in the single quotes. here are some valid character constants are-

Invalid

Remarks

‘lion’

There should be only one character within quotes

“N”

Double quotes are not allowed

X

single quotes missing

There is no character between single quotes

Note: Every character has unique integer value. so every associated value or integer value is machine code such as ASCII(American standard code for information interchange). its depend on machine if machine using ASCII then A character represent by 65

Here are Some ASCII values are-

A-Z

ASCI value(65-90)

a-z

ASCI value(97-122)

0-9

ASCI value(48-57)

;

ASCI value(59)
String Constant in C++

A string Constant is a group of characters enclosed within double quotes(“”). At the end of string the complier automatically placed null character (‘\0’). Here are some examples of String constants-

“Saraswat”
“Nitish”
“897”
“5”
” “
“,”

Symbolic Constant in C++

if in program we want to use constant as several times, we can given it a name. such as if we use 3.1414587 at many times in a program. We can give it a name PI, and uses it name PI . where we need instead of writing the constant value anywhere. These types of constant are known as Symbolic constant.

#define PI 3.141567
#define name “Nitish”
#define CH ‘c’

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise