3 min read

BASICS

Just like all languages c++ also have a well-maintained set of characters, symbols, integers, etc.

CHARACTER SET

It is defined as a set of valid characters that can be used in c++. It consists of :

TOKENS

These are the smallest individual unit in a program. There are 5 types of tokens:

KEYWORDS –

The reserved word in c++, which already have some meanings are known as keywords. C++ Language supports more than 64 keywords, of which 32 are also present in C.

Every Keyword exists in lower case latter like auto, break, case, const, continue, int etc

IDENTIFIERS –

These are used as general terminology for the names given to different parts of program viz. variables, objects, etc.

Rules for Identifiers

 When naming an identifier, follow these established rules:

  • An identifier cannot be a C++ keyword. Keywords have predefined special meanings to the compiler.
  • It cannot have two consecutive underscores.
  • It can be a combination of numbers, letters, connectors, and Unicode characters.
  • It must start with a letter of the alphabet or an underscore, not a number.
  • It should not include white space.
  • It cannot have more than 511 characters.
  • It has to be declared before it is referred.
  • Two identifiers cannot have the same name.
  • Identifiers are case sensitive.

iii.   LITERALS- Literals are the data items that are constants i.e, they never change their value during a program run. There are several kinds of literals

 1. Bool literals: It is used to represent boolean values ( true or false/0 or 1).

 size required -1 bit.

2. Integer Constants: They are the whole numbers without a fractional part.

They can be of 3 types:

  • Decimal
  • Octal
  • Hexadecimal.

Rules for Integer constants

  • It must have at least one digit and must not contain any decimal point.
  • It may contain either + or – sign. A number with no sign is assumed to be positive.
  • Commas cannot appear in integer constant.

3. Character Constants: A Character constant is one character enclosed in single quotes as in ‘z’. The character used for a character literal may be any character, except for the reserved characters backslash (‘\’), single quotation mark (‘), or newline. Reserved characters can be specified by using an escape sequence. Characters may be specified by using universal character names, as long as the type is large enough to hold the character.

4. String literals: String literals are enclosed in double-quotes. A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters. Size of string literal is the number of characters plus 1 for the terminating null character. For example – ‘abc‘ size is 4.

 If you liked my post Please share and follow me on @priya123..

Categories: Uncategorized

0 Comments

Leave a Reply