[go: up one dir, main page]

0% found this document useful (0 votes)
6 views7 pages

02_dataType

The document provides an overview of data types in C, categorizing them into primitive (char, int, float, double) and non-primitive types (Array, Structure, Union, function). It also covers the size of each data type, keywords, variable declaration rules, and various operators including arithmetic, assignment, relational, logical, and bitwise operators. Additionally, it explains the use of format specifiers and the comma operator in C programming.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

02_dataType

The document provides an overview of data types in C, categorizing them into primitive (char, int, float, double) and non-primitive types (Array, Structure, Union, function). It also covers the size of each data type, keywords, variable declaration rules, and various operators including arithmetic, assignment, relational, logical, and bitwise operators. Additionally, it explains the use of format specifiers and the comma operator in C programming.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

-------------------------------------------------------------------------

Data type in c
-------------------------------------------------------------------------

1. Primitive data type

- char
- int
- float
- double

2. Non primitive data type

- 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
-------------------------------------------------------------------------

Keyword is predefined or reserved known as keyword.


Keyword cannot be used as identifier or variables.
Total keyword 32 in c.
-------------------------------------------------------------------------
Variable in c
-------------------------------------------------------------------------

- Variable like box or container.

How to make variable.

- Lowercase, uppercase, underscore;

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
-------------------------------------------------------------

1. Arithmetic operator (+ - / * %);

Example:

void main()
{

int num1 = 45,num2 =65;


printf("Addition is : %d\n",num1+num2);
printf("Subtract is : %d\n",num1-num2);
printf("Product is : %d\n",num1*num2);
printf("Division is : %d\n",num1/num2);
printf("modulus is : %d\n",num1%num2);
getch();
}

2. Assignment operator (=, +=, -=, /=, *=);

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();
}

3. Increment or decrement (++) (--)


(++) means incremented by 1
(--) means decremented by -1
- prefix (++a or --b)
- postfix (a++ or b--)
Example:
void main()
{
float f1=2.3, f2 = 5.3;
f1++; //2.3 >> 3.3
++f2;// 6.3
f2 = f1;//
printf("f1 = %f, f2 =%f",f1,f2);//3.3,3.3
}

void main()
{
int n1=6, n2 = -2,test;
n2++;// -2
n2=n1+n2;//
n1 -= n2;//
printf("n1 = %d, n2 = %d",n1,n2);
}

4. Relational operator (>, <, <=, >=, ==)

Syntax:
(Condition)? Statement 1: statement 2;

Example:
ACSII values
American code standard information for interchange.

int n1 = 45, n2 = 67, n3 = 0;


n1 = n2 = n3=2;
(n1<= n3)? printf("true") : printf("false"); //
(n3>= n2)? printf("true") : printf("false"); //
(n3== n1)? printf("true") : printf("false"); //
(n3! = n3)? printf("true") : printf("false"); //

5. Logical operator
- And (&&)
- Or (||)
- Not (!)
(AND) &&
True= 1
False = 0

Condition 1 condition 2 result

True True True


False True False
True False False
False False False

(OR) ||

Condition 1 condition 2 result

True true true


False true True
True false true
False False False

NOT (!)

True - False
False - True

Example:

int n1 = 45, n2 = 67, n3 = 0;

(n1<= n3) && (n1!= n3) ? printf("true") :


printf("false"); // false
(n3>= n2) || (n1== n3) ? printf("true") :
printf("false"); // false
(n3== n1) && (n2<= n3) ? printf("true") :
printf("false"); // false
(n3!= n3) ||!(n3 ==n3) ? printf("true") :
printf("false"); // false

6. Conditional or ternary operator

(Condition)? statement1: statement2;

7. Bitwise

- And (&)
- Or (|)
- (complement) (~)
- Not (!)
- Xor (^)

int a = 2;
// Bit presentation 10

int b = 3;
// Bit presentation 11
int linebreak = "<br />";

printf("(a & b) => ");

a=0010
b=0011
------------
2=0010

Result = (a & b);


printf(result);
printf(linebreak);
printf("(a | b) => ");
result = (a | b);
printf(result);
printf(linebreak);
printf("(a ^ b) => ");
result = (a ^ b);
printf(result);
printf(linebreak);
printf("(~b) => ");
result = (~b);
printf(result);
printf(linebreak);
printf("(a << b) => ");
result = (a << b);
printf(result);
printf(linebreak);
printf("(a >> b) => ");
result = (a >> b);
printf(result);
printf(linebreak);

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

Comma operator use for separated…


Ex:

int a,b,c,d,e,f;// comma operator use with declaration of variables.

add(int a, float b, double c); // comma operator use with


arguments;

Square (int, int) //

You might also like