The if keyword allows a course of action to be based on the outcome of a condition. The general form of the if statement is
if(
condition
) {
statement block 1
} else {
statement block 2
}
If single statements are used, the braces are not needed. The else is optional.
The
condition
may be any expression. If that expression
The following fragment checks if x is greater than 10:
if(x > 10) cout << "x is greater than 10."; else cout << "x is less than or equal to 10.";
C99 includes the keyword
_Imaginary
, which supports complex arithmetic. However, no implementation is required to implement imaginary types and freestanding
float _Imaginary double _Imaginary long double _Imaginary
The reason that
_Imaginary
, rather than
imaginary
, was specified as a keyword is that many existing C programs had already defined their own custom imaginary data types using the
The header < complex.h > defines (among other things) the macro imaginary , which expands to _Imaginary . Thus, for new C programs, it is best to include < complex.h > and then use the imaginary macro.
The
inline
The following tells the compiler to generate inline code for myfunc( ) :
inline void myfunc(int i) { // ... }
When a function’s definition is included within a class declaration, that function’s code is automatically inlined, if possible.
int
is the type
long
is a data type modifier used to declare long integer or floating-point
The
mutable
The namespace keyword allows you to partition the global namespace by creating a declarative region. In essence, a namespace defines a scope. The general form of namespace is shown here:
namespacename { // declarations }
In addition, you can have unnamed namespaces as shown here:
namespace { // declarations }
Unnamed namespaces allow you to establish unique identifiers that are known only within the scope of a single file.
Here is an example of a namespace :
namespace MyNameSpace { int i, k; void myfunc(int j) { cout << j; } }
Here, i , k, and myfunc( ) are part of the scope defined by the MyNameSpac e namespace.
Since a namespace defines a scope, you need to use the scope resolution operator to refer to objects defined within one. For example, to assign the value 10 to i, you must use this statement:
MyNameSpace::i = 10;
If the
using namespace name; using name::member;
In the first form,
name
specifies the name of the namespace you want to access. All of the members defined within the specified namespace can be used without qualification. In the second form, only a specific member of the namespace is made visible. For example,
using MyNameSpace::k; // only k is made visible k = 10; // OK because k is visible using namespace MyNameSpace; // all members of MyNameSpace are visible i = 10; // OK because all members of MyNameSpace are now visible