C++ Fundamentals

C++ keywords
C++ keywords

Tokens: smallest individual units used in a program.

The tokens in C++ are: keywords, identifiers, constants, variables, strings, operators.

A C++ program is written using these tokens and white spaces (blank space).

  • Keywords/reserved words: The keywords implements specific C++ language features.
  • They are explicitly reserved identifiers and cannot be used as names for the program variables or other user-defined program elements.
  • The C++ keywords are given next.
C++ keywords
Figure:   C++ keywords

Identifiers: refers to the names of variables, functions, arrays, classes, etc. created by the programmer.

They are the fundamental requirement of any language.

The naming rules in C++ are:

  • Only alphabetic characters, digits and underscores are permitted.
  • Names can not start with a digit.
  • Uppercase and lowercase letters are distinct.
  • A keyword can not be used as a user defined identifier.

Constants – refer to the fixed values that do not change during the execution of a program. Two types of constants:

Literal constants – include integers, characters, floating point numbers and strings. Literal constants do not have memory locations (stay with instructions).

  • Integer constants: 2, -2, 1213
  • Floating point constants: 2., 2.0, -3.14, 1.24E01
  • Character constant: any character within single quotation. eg. ‘A’, ‘2’, ‘+’
  • String constant: Any text within double quotation. eg. “23/2, Bagmara Road”,
  • “2+3”, “BAU, Myn.”, “+”, “-2”

Symbolic/Named constants: Name given to a literal constant. eg. pi is a symbolic constant which equals 3.14159. We can also give name say, title for the string constant “BAU, Myn.”.

Symbolic constants need memory location for its storage. You must declare symbolic constants before its use. When you declare a symbolic constant, you must give its value. Example,

const max=12 or const int max=12; //int const

const float pi=3.14159; //real const

const char[] title=”BAU, Myn.”; //string const

const char yesno=’y’; //character const

If we don’t specify data type, it defaults to int.

 

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*