Basics
What is C++?
C++ is an abstraction programming language (not just an extension of C but a High Level abstraction language that comes at no cost in performance )
Who calls main()
C or C++ runtime library calls main(), example in GCC C , main is called by _start() function
What are the process in compilation
preprocessing , compiling , assembling , linking
->preprocessing does text replacement , # define , and #includes are replaced
-> compiling takes individual files and converts to intermediate file
-> assembling converts the text file to assembly (target machine dependent example x86 or arm)
-> creates a single binary output file
data types and standard ?
-> built in data types / primary data types
-> user defined data type
bool, char (unsigned / signed char char8_t, char16_t char32_t wchar_t etc) , int float , double
Standard enforces a minimum size but implementation can be compiler dependent
don't assume if standard doesn't specify something it will be implementation dependent and will result in ambiguous results
Initialization older versus Uniform initialization
unsigned int a= -20 ; // no error with old initialization
with unsigned int a{-20}; // error detected , narrowing not allowed implicitly
type deduction using auto and decltype(fn()) x;
use auto for initializer while decltype for complex expressions and function return
example : auto d{12.2}; // this is double
auto f_value{12.2F}; //this is float
using auto a= {123}; // results in list of integer
becomes -> std::initiliser_list<int> a = std::initiliser_list<int> {111};
using : int a={123}; // directly will result in initializer not as list but normal int , only with auto it works
using auto makes type deduction , makes code easier to read and makes it easier to change
code:
using decltype is for type deduction if no initial value is known but type of an function or expression needs to be evaluated
note : to print type in C++ use : typeid(i).name(); // if i is int d is printed for float F is printed
pvallue , lvalue , prvalue , gvalue , xvalue
lvalue has a name / identity and usually present to the left of an expression or assignment
rvalue (a value thats returned from a function for example) doesnt have an identity and is not an lvalue
prvalue: pure r value is a subset of rvalue , same like rvalue it doesnt have a name / memory address that can be identified example : int a = 1+2 ; // 1+2 is a prvalue
int {a+b}; // is prvalue , no identity but expression
glvalue : similar to lvalue , the expression computes to an object or a function
xvalue : expiring vaue (like out of scope object?) value that has an identity but can be reused
nullptr is of type std::null_ptr and can be used for ptr only unline NULL that can represent 0 (int) as well as NULL for pointer
Last updated