C

Type casting in C

Në shqip: Konvertimi i tipit në C

ShpjegimiSQ

Në C e konverton një vlerë duke shkruar tipin në kllapa: (double)shuma / n. Kujdes: (int)3.99 jep 3 — pjesa pas presjes thjesht pritet, s'rrumbullakoset.

EnglishEN

In C you convert a value by writing the type in brackets: (double)sum / n. Careful: (int)3.99 gives 3 — the decimal part is just chopped off, not rounded.

Si ta mendosh

Si ta derdhësh lëngun në një gotë më të vogël: diçka mund të humbasë.

Lexoje në anglisht

Like pouring juice into a smaller glass: some might be lost.

Shembull kodic

int shuma = 7, n = 2;
double m = (double)shuma / n;   // 3.5
int i = (int)3.99;               // 3

Terma të lidhur