C Basics
02 - data representation, variables, data types, scanf & printf
/AhmedHatemS
/c/AhmedHatemS
What is the content?
1. Binary VS decimal number system
2. ASCII code
3. Variables.
4. Data types.
5. Conversion Specifiers
6. Scan and print (scanf, printf)
7. Program to get the area of a rectangle.
Binary vs decimal number system
• In our real life we have digits from 0 to 9, and we can use them to
represent any number.
• In the machine language we only have two values for every bit. if it is
on, that means 1, and if it is off, that means 0. So, we can use 0s and
1s to represent any thing.
ASCII code
American Standard
Code for Information
Interchange.
Note that:
Variables
C & C++ are case
• The name of a variable: sensitive.
➢ can’t be a number (0 – 9)
➢ Can’t be a special character ( @, #, $, *, %, !, -, …etc.)
➢ the first character can't be a number (1var, 2name, …etc.)
➢ The first character can’t be a special character (#var, *me, …etc.)
➢ The variable name can’t be a reserved word (int, float, if, switch, case, try, set, catch, …etc.)
➢ Can be a character or start with character, start with underscore , contains numbers or ends
with them (variable1, f1st, i, j, _var, …etc.)
Before using a variable,
Data types we need to declare /
initialize it.
Float has a precision of
8 bits / 1 byte
seven digits.
0.1234567
Double has a precision
of fifteen digits.
0.123456789123456
Conversion Specifiers
Data type Format specifier
char %c
short %d
Int %d
long %l or %dl
float %f
double %f or %lf
string %s
Scan and print
• We use scanf(); to get input from the user and use printf(); to print
output on the screen.
• We can use gets(); and puts(); in some cases. Both the functions are
involved in the input/output operations of the strings.
memory
Length 5
width 3
area 15
Next video