Skip to content

Latest commit

 

History

History
113 lines (99 loc) · 3.18 KB

FP_22_C_2021-11-04.md

File metadata and controls

113 lines (99 loc) · 3.18 KB

TIPURI NUMERICE DE DATE

1. Tipuri intregi

Denumire tip         |	Numar octeti |	Interval definit
---------------------|---------------|---------------------------
unsigned char        |      1        | (00000000)2 -> (11111111)2
	             |	             | (0)10 -> (255)10
---------------------|---------------|---------------------------
(signed) char        |      1        | (-128)10 -> (127)10
---------------------|---------------|---------------------------
unsigned short (int) |      2        | (0)2 -> 2^16 = (65535)10
---------------------|---------------|---------------------------
(signed) short (int) |      2        | (-32768)10 -> (32767)10
---------------------|---------------|---------------------------
unsigned int         |      4        | 0 -> (2^32)-1
unsigned long        |               |
---------------------|---------------|---------------------------
(signed) int         |      4        | -(2^31) -> (2^31)
(signed) long        |               |
---------------------|---------------|---------------------------
long long            |      8        | -(2^63) -> (2^63)-1
---------------------|---------------|---------------------------
Operatori:
+ 	suma
- 	diferenta
* 	inmultire
/ 	impartire
++ 	incrementare
-- 	decrementare
int n=1;
int m=n++; //m=1; n=2;
m=++n; //m=3; n=3;  mai rapid decat n++

i+=1;  //mai lenta decat i++ 

=
+=
-=
*=
/=
%=

Operatori de shiftare (mutare, trecere peste): << >>

v<<m; //se shifteaza m biti catre stanga in v

unsigned v=5;
int x=v<<2; //<=> x=v*(2^2)
00000101 (5)10
     <--2
00010100 (20)10


v=5;
x=v>>1; // <=> x=v/(2^1)

00000101 (5)10
  1-->
00000010 (2)10

Shiftare cu atribuire stanga/dreapta: <<= >>=

Operatorii pe biti:

binari & si sau ^ sau exclusiv unar ~ not

a=   10110110
b=   10011100
a&b= 10010100
a|b= 10111110
a^b= 00101010
~a=  01001001

2. Tipuri reale/in virgula mobila de date

Tip date             |	Numar octeti | Domeniu in valoare absoluta
---------------------|---------------|----------------------------------
float		     |      4        | 3,4*(10)^(-38) -> 3,4*(10)^38
---------------------|---------------|----------------------------------
double               |      8        | 1,7*(10)^(-308) -> 1,7*(10)^308
---------------------|---------------|----------------------------------
long double          |     10        | 3,4*(10)^(-4000) -> 1,1*(10)^4000
---------------------|---------------|----------------------------------

Domeniul de valori este extrem de generos, insa cu cat tipul de date real este mai mare (pe mai multi octeti) cu atat exista mai multe cifre exacte si in consecinta calculele sunt mai precise.

Operatori:
+ - * /
= += -= *= /=
!

In C standard nu exista un tip boolean special. In schimb, orice valoare numerica poate fi folosita ca o valoare booleana, astfel, orice valoare intreaga diferita de 0, In C este considerata ca valoare avand valoarea true, iar orice numar 0 reprezinta valoarea booleana false. -0.00000001 true Are sens definirea operatorului ! NOT boolean pe orice valoare numerica. !-0.00000001 == 0. Are sens: !x && y x==0 && y!=0 x este 0 si y diferit de 0.