- White-space is completely ignored by compiler : Not True. There are few restrictions apply to this rule. e.g.
- Preprocessor directives must be in same line.
- ‘cout’ could not be broken.
- Cout, Cin are objects : These are overloaded. Cout – ‘<<‘ (Put to or insertion operation) and ‘>>’ (extraction or get operator).
- Directives :
- Preprocessor Directives :
- Starts with #
- It is an instruction to compiler’s preprocessor part.
- usually adds header type file are included using it.
- Using Directive :
- C++ program can be divided into different name spaces. using tells the name of namespace.
- Namespace is a part of program in which some names are recognised, outside which they are unknown.
- e.g. using namespace std; –> In ‘std’ namespace various program components such as cout are declared.
- If we don’t use ‘std’ then we have add std name to many program elements e.g. – std::cout << “xyz”;
- Preprocessor Directives :
- Header files (include files) :
- Newer standard c++ header files don’t have a file extension, but older from the time of c have extension ‘.H’.
- Header files contains names and types of library functions.
- Integers :
- Commonly used is ‘int’ but there are many sized of ‘int’ available (depends on compiler).
- Amount of memory occupied by the integer type is System Dependent. A 32 bit system have 32 bit int (4 bytes, Range : -2,147,483,648 to 2,147,483,647).
- The range occupied by various types are listed in the header file ‘LIMITS’.
- Other integer types :
- Long, Short, Char are Integer types and have fixed size as opposed to int.
- Long is of 4 bytes. This helps on systems where int is limited to 2 bytes.
- Short is of 2 bytes ( Range : -32,768 to 32,767). This is only used to save some memory. But we rarely use it because int is faster to access than short.
- Constant of type long can be declared as :
- longvar = 76L;
- Many compilers provide various sizes of int : These types are preceded by two underscores. They are __int8, __int16, __int32 and __int64. The __int8 corresponds to a char.
- For bigger char size c++ have type wchar_t. Because in 1 byte we cannot accommodate many language characters.
- Escape Sequences :
\xdd is used to represent character above 127 range in hexadecimal notation e.g. \xB2
- Declaration and Definitions : A declaration introduces a variable’s name into a program and specifies its type. However, a declaration also sets aside memory for the variable, it is also called a definition.
- The ‘endl’ manipulator : endl inserts linefeed into the stream.
- Manipulators are instructions to the the output stream, that modify the output in various ways.
- endl and ‘\n’ difference : endl causes the output buffer to be flushed.
- Library Functions : These functions perform file access, mathematical computations and data conversion. These functions are stored in library files having extension ‘.LIB’.
- Header files and Library files : Header files contains the names and types of the functions and other elements in the library files.
- Two ways of #include
- #include <header.h> : Starts search from default INCLUDE directory.
- #include “header.h” : Starts search from current directory.
- No difference between the two. But if we tell the place of header file then the compilation process becomes somewhat fast.
- ‘const’ keyword is used to stipulates that the value of variable will not change.