# Basics

1. 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 )

2. Who calls main()

C or C++ runtime library calls main(), example in GCC C , main is called by \_start() function

3. What are the process in compilation

preprocessing , compiling , assembling , linking

->preprocessing does text replacement , # define , and #includes are replaced&#x20;

-> compiling takes individual files and converts to  intermediate file&#x20;

-> assembling converts the text file to assembly (target machine dependent example x86 or arm)

-> creates a single binary output file

4. 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&#x20;

**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**

5. 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&#x20;

6. 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**

7. **using auto makes type deduction , makes code easier to read and makes it easier to change**&#x20;

**code:**

```cpp
#include<iostream>
#include<vector>
#include<list>

void func(std::vector<int> &a)
{

for(std::vector<int>::iterator i = a.begin(); i!= a.end();  ++i)
std::cout<<*i;

}

int main(){
std::list<int> p ={1,2,3,4,5}; // list of int
std::vector<int> q = {1,2,3,4,5,6,7};

func(q);
//func(&q);

}
//////////////////////////////////////

//using auto keyword

#include<iostream>
#include<vector>
#include<list>

void func(std::list<int> &a)
{

for(auto i = a.begin(); i!= a.end();  ++i)
std::cout<<*i;

}

int main(){
std::list<int> p ={1,2,3,4,5}; // list of int
std::vector<int> q = {1,2,3,4,5,6,7};

//func(q);
func(&q);

}


```

**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*

8. *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*&#x20;

**glvalue** : similar to lvalue , the expression computes to an object or a function&#x20;

**xvalue** : expiring vaue (like out of scope object?) value that has an identity but can be reused&#x20;

9. **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**

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://amriths-harijayanthan.gitbook.io/notes/c++-programming/basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
