02_dataType
02_dataType
Data type in c
-------------------------------------------------------------------------
- char
- int
- float
- double
- Array
- Structure
- Union
- function
-------------------------------------------------------------------------
Size of data type
-------------------------------------------------------------------------
char - 1 byte
int - 2 byte
float - 4 byte
double - 8 byte
1 byte - 8bit
1 kb(kilo byte) - 1024 byte
1 mb(megabyte) - 1024 kb
1 gb(gaga byte) - 1024 mb
1 tb(tera byte) - 1024 gb
-------------------------------------------------------------------------
Keywords in c
-------------------------------------------------------------------------
Ex:
abc; valid
a_b;
1a; invalid
1212; invalid
#2; invalid
a b c; space not allow
a_b_c=9;
name;
a=2,b=3,c=23;
-------------------------------------------------------------
What is identifier?
-------------------------------------------------------------
Token in c
- Special character
- Keywords
- Identifier
- Operators
-----------------------------------------------------------
FORMAT SPECIFIER
char - %c
int - %d
float - %f
double - %f or %lf
string - %s
sizeof - %u
long int - %ld
pointer - %p
-------------------------------------------------------------
Operators in c
-------------------------------------------------------------
Example:
void main()
{
Example:
void main()
{
int num1 = 45,num2 =65;
printf("Addition is : %d\n",num1+num2);//110
printf("num1 = %d, num2 = %d",num1,num2);
//45, 65
printf("Addition is :
%d\n",num1+=num2);//110
printf("num1 = %d, num2 = %d",num1,num2);
//110, 65
printf("Subtract is : %d\n",num1-=num2);
printf("Product is : %d\n",num1*=num2);
printf("Division is : %d\n",num1/=num2);
getch();
}
void main()
{
int n1=6, n2 = -2,test;
n2++;// -2
n2=n1+n2;//
n1 -= n2;//
printf("n1 = %d, n2 = %d",n1,n2);
}
Syntax:
(Condition)? Statement 1: statement 2;
Example:
ACSII values
American code standard information for interchange.
5. Logical operator
- And (&&)
- Or (||)
- Not (!)
(AND) &&
True= 1
False = 0
(OR) ||
NOT (!)
True - False
False - True
Example:
7. Bitwise
- And (&)
- Or (|)
- (complement) (~)
- Not (!)
- Xor (^)
int a = 2;
// Bit presentation 10
int b = 3;
// Bit presentation 11
int linebreak = "<br />";
a=0010
b=0011
------------
2=0010
void main()
{
int a = 2, b = 3,result;
clrscr();
result = a&b;
printf(" result = %d\n",result);
result = a|b;
printf(" result = %d\n",result);
result = a^b;
printf(" result = %d\n",result);
getch();
}
8. Comma operator