Professional Documents
Culture Documents
Fundamentals of The C Programming
Fundamentals of The C Programming
Fundamentals of The C Programming
CHAPTER 2
FUNDAMENTALS OF THE C PROGRAMMING
OUTLINE
¡ Variables
¡ Intro to Data Types
¡ Int, Float and Double Data Types
¡ Char Data Type and ASCII table
¡ Operators
¡ Type Casting
VARIABLES
Address Value
myNumber
00193959A02F 23
Computer Memory
iPhone eBay
getDeletedRecords()
INTRO TO DATA TYPES
values
int float char void Arrays
unsigned
long int double char Union
long
short int double
unsigned
...
NUMERIC DATA TYPES
¡ A real number has an integral part and a fractional part that are
separated by a decimal point.
¡ In C, the data type double is used to represent real numbers. For
example:
3.141592 2.85 150.0
¡ Double types in C:
#include <stdio.h>
int main() {
char x;
scanf("%c", &x);
printf("%c", x); printf(“%c”,x)
return 0;
}
ASCII AND INT CONVERSION
X = 5 + 8;
¡ There are following three types of operators in C language:
¡ Arithmetic Operators: +, -, *, /, %
¡ Increment and Decrement Operators: ++, --
¡ Assignment Operators: =, +=, -=, *=, /=, %=
¡ Relational Operators: <, <=, >, >=, ==, !=
¡ Logical Operators: &&, ||, !
¡ Bitwise Operators: &, |, <<, >>, -, ^
¡ Ternary Operators: ?:
ARITHMETIC OPERATORS
¡ The moduls operator (%) returns the remainder left over when
one operand is divided by a second operand.
¡ For example, 6 (slices) % 5 (eaters) will result in 1
1 left over
INCREMENT AND DECREMENT OPERATORS
int i = 2 int i = 2
i = i + 1 i = i - 1
C JavaScript
BASIC TYPE CASTING
1 quarter
#include <stdio.h>
int main()
{
int x = 10; // integer x
char y = 'a'; // character c
(data type) x
¡ For example:
¡ (double)a ¡ (int)(5.6*4)
¡ (int)2.5 ¡ (double)(2+(int)3.4)
¡ 10/(float)2
¡ (float)2+3
EXERCISE 1
¡ Variable declaration :
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = 'W';
unsigned long ux = 2541567890;
¡ Write a C program to display;
a + c, x + c, dx + x, ((int) dx) + ax, a + x, s +
b, ax + b, s + c, ax + c, ax + ux
EXERCISE 2
3 Note(s) of 100.000
1 Note(s) of 50.000
1 Note(s) of 20.000
0 Note(s) of 10.000
1 Note(s) of 5.000
0 Note(s) of 2.000
0 Note(s) of 1.000
EXERCISE 4
¡ Variables
¡ Intro to Data Types
¡ Int, Float and Double Data Types
¡ Char Data Type and ASCII table
¡ Operators
¡ Type Casting