C++
C++
Features:
supports data abstruction, means Data abstraction is a fundamental concept in
computer science and software engineering that involves hiding the
implementation details of data types and exposing only the essential features
or behaviors to the outside world. Data abstraction is a powerful concept that
facilitates the design, implementation, and maintenance of complex software
systems by providing clear interfaces, encapsulating implementation details,
promoting modularity, and supporting information hiding.
-----------------------------
-----------------------------------------
input For Space separated word
*** Modifier like signed, unsigned used integral data type as decimal number/ whole number.
Can’t use for float, double(2.0, 2.5).
Float and Double:
**Precision includes digits before decimal point(.). 12547.325-> 12547 included in the
precision.
For Float: 12345.6789-> 89will be garbage value. Cause precision 7 for Float. May print like:
12345.6725
** float a=123456789-> 89 will b garbage value. May print like: 12345.6745
Floatiing point number memory representation is not similar to deciaml number. It explained in
IEEE_754 -> IEEE_754-> Press ctrl &Click
cout<<setprecision(20);
used for set precision. Library> #include<iomanip>
suffixes(like f, L): u // unsigned
ul // unsigned long
ll // long long
-------------------------------------xxx--------------------------------
**Booleans occupy 1byte/8bits in memory.
bool x=true;
bool y=false;
cout<<boolalpha; //used for printf true/false instead of 0/1
cout<<x<<” ”<<y;
will print true, false.
----------------------------------------
Character:
------------------------------
* std:flush: when we print something, it does not go directly to the terminal. It store somewhere
called “buffer”. When buffer is full/ complete it goes to terminal. If use std:flush data directly goes
to console/terminal instead of goes to buffer.
*setw() : set width
cout<<right; // printf from right. Left for left alinement
--------------------------
#include<cmath> : abs(), pow(), ceil(), log(), sqrt(), sin(), tan() etc
https://en.cppreference.com/w/cpp/header/cmath
for log(): log(10) means loge(10). So have to fix the base as log10(10). E=2.71..
* round(): 3.5 will make 4, and 3.49 will make 3.
-------------------------------
if we take data type less than 4 byte and perform arithmatic operation compiler
automatically convert it to 4 byte. This behavior also present on other operator like bitwise
operator.(>>, <<)
-----------------
flow control: if else, switch, ternary operator.
*Switch: if we not use “Break”, the case which match, after that all case will execute and
print every case value.
*we can use int, char , double, enum etc but not string as case.
--------------------------------------
*if we use “const” before array. We cant modify array elements.
*a[ ]={2,3,7,5,2,3}; size(a) return the size of array. /Or sizeof(a)/sizeof(a[0]);
Pointer
Memory Map
When we run a program it runs on RAM. Verious program of OS or other is running on
memory.
This process thinks it own 0~2N amount of memory which is virtual memory.
When we run a program it is going to go through a PCU section called memory
management unit(MMU).
Part that are likely not to be used are discarded from the RAM.
MMU realy does is, helps us mapping between the memory map in ur program and the real
thing we have in RAM.
If we run few program, they are going to go through MMU and MMU is going assign them
real section on RAM
* Since program thinks it 2n -1memory, The MMU is going to transform between the idea
the program has and the RAM we have(assigned memory by MMU).
* The memory map/Structure of program is standard format defined by OS. Thats why we
cant run directly window program on Linux.
*Memory map is divided into a lot parts
* STACK: Local variable stores on stack section.
* print, statement, function others store on stack section.
* TEXT:Actual binary load on Text so that CPU can execute it.
* HEAP:Additional memory when we run out of stack memory also to make things better
for program, Used for run time.