Skip to main content

Posts

Showing posts with the label Cpp Declaration and Assignment

C++ Tokens

Declaration & Assignments C++ Tokens As mentioned earlier, C++ is the superset of  C  and so most constructs of C are legal in C++ with their meaning and usage unchanged. So tokens, expressions and data types are similar like that of C. It also is preferred to understand the concepts of C before learning C++. However there are some exceptions and additions in C++ which you will not get in C. In this chapter you will learn about what are tokens, and the different types of tokens, expressions, and basic data types. What are Tokens Each individual word and punctuation is referred to as a token in C++. Tokens are the smallest building block or smallest unit of a C++ program. These following tokens are available in C++: Identifiers Keywords Constants Operators Strings Identifiers : Identifiers are names given to different entries such as variables, structures and functions. Also identifier names should have to be unique because these entities are used in the execution of the pr...

C++ Keywords

Declaration & Assignments C++ Keywords The C++ Keywords must be in your knowledge because you can not use them as variable name. C++ Keywords List You can’t use keyword as identifier in your C++ programs, its reserved words in C++ library and used to perform an internal operation. asm else new this auto enum operator throw bool explicit private true break export protected try case extern public typedef catch false register typeid char float reinterpret_cast typename class for return union const friend short unsigned const_cast goto signed using continue if sizeof virtual default inline static void delete int static_cast volatile do long struct wchar_t double mutable switch while dynamic_cast namespace template In addition, the following words are also reserved: And bitor not_eq xor and_eq compl or xor_eq bitand not or_eq You should also try to avoid using names from the C++ library, e.g. swap, max.

C++ Constants

Declaration & Assignments C++ Constants Constants are like variable, except that their value never changes during the program execution once defined What are Constants? Constants refer to as fixed values, unlike variables whose value can be altered, constants – as the name implies does not change, they remain constant. Constant must have to be initialized at the time of creating it and new values cannot be assigned later to it. Constants are also called literals. Constants can be any of the data type. It is considered best practice to define constants using only upper-case names. Constant Definition in C++ There are two other different ways to define constants in C++. These are: By using  const  keyword By using  #define  preprocessor Constant Definition by Using  const  Keyword Syntax: const type constant_name ; Example: #include   <iostream> using namespace std ; int main () { const int SIDE = 50 ; int area ; area = SIDE * SI...

C++ Operators

Declaration & Assignments C++ Operators C++ operator is a symbol that is used to perform mathematical or logical manipulations. C++ language is rich with built-in operators. Arithmetic Operators Operator Description + Addition – Subtraction * Multiplication / Division % Modulus Increment and Decrement Operators Operator Description ++ Increment −− Decrement Relational Operators Operator Description == Is equal to != Is not equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to Logical Operators Operator Description && And  operator. Performs a logical conjunction on two expressions. (if both expressions evaluate to True, result is True. If either expression evaluates to False, result is False) || Or  operator. Performs a logical disjunction on two expressions. (if either or both expressions evaluate to True, result is True) ! Not  operator. Performs logical negation on an expression. Bitwise Operators Operator Desc...

C++ Data Types

Declaration & Assignments C++ Data Types Data types in any of the language means that what are the various type of data the variables can have in that particular language. Information is stored in a computer memory with different  data types . Whenever a variable is declared it becomes necessary to define data type that what will be the type of data that variable can hold. Data Types available in C++: Primary(Built-in) Data Types: character integer floating point boolean double floating point void wide character User Defined Data Types: Structure Union Class Enumeration Derived Data Types: Array Function Pointer Reference Both C and C++ compilers support the fundamental i.e. the built-in data types. Taking void as exception, the basic data types may have several modifiers, and these modifiers are used to serve the data types in various situations. The lists of modifiers used in C++ are: signed unsigned long short Character Data Types Data Type (Keywords) Description Size Typica...

For Programs Click Here