Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Number

Numeric Types

Employ the int data type for storing whole numbers without decimals, such as 35 or 1000, and use float or double for floating-point numbers with decimals, like 9.99 or 3.14515.

int

int myNum = 1000;
printf(“%d”, myNum); 

float

float myNum = 5.75;
printf(“%f”, myNum); 

double

double myNum = 19.99;
printf(“%lf”, myNum); 

 

float vs. double

The precision of a floating-point value determines the number of digits it can have after the decimal point. Float variables typically have a precision of six or seven decimal digits, while double variables offer a precision of around 15 digits. Consequently, it’s generally advisable to use double for most calculations due to its higher precision. However, it’s important to note that double requires twice as much memory as float (8 bytes vs. 4 bytes).

 

Scientific Numbers

A floating-point number can also be represented in scientific notation using an “e” to denote the power of 10.

Example

float f1 = 35e3;
double d1 = 12E4;

printf(“%f\n”, f1);
printf(“%lf”, d1);