Syllabus
Overview of C
|
Token
|
Structure of C program
|
Input output operation
|
Control statement
|
Compilation and execution of C
|
Structure
|
String handling
|
Function
|
Array
|
Pointer
|
Library function
|
Header file
|
File handling
|
Preprocessor directive
|
Union
|
#Overview of C:-
- History of C
- Advantage of C
- Disadvantage of C
- Application use of C
History of C
- C is the high level language and general purpose programming language.
- It was developed by Dennis Ritchie at AT & T Bell laboratory in 1972.
- AT&T stands for American Telegraph and telecommunication this lab is located in USA .
- C language is derived from B and BCPL(Basic combined programming language).
- Its main objective is to developed system software such as operating system ,compiler ,interpreter linker, loader etc .
- Unix operating system is written within C language .
- C is a case sensitive language its mean lowercase is not equivalent to uppercase ABC not abc.
- it is compiled based language.
Advantage of C
- C support procedural programming language and structure modular conventional programming function oriented programming.
- It is the traditional method that is used to reduce the complexity of program in this case a program is divided into multiple parts that part is called function module.
- In this case we can write source code of any particular method according to requirement.
- C supports both high level and low level programming language so it is also known as mid or middle level language.
- It support system programming in this case we can design compiler interpreter operating system etc
- It also supports application programming such as school management system , automation system Supermarket etc.
- C support rich set of library functions such as mathematical function conversion function date and time function.
- It supports graphic programming in this case we can design human face car umbrella
- It support game programming due to graphics
- Its execution is past due to compiler based language
- It is portable because it can be executed on different operating system such as Windows Linux Unix Solaris Macintosh(MAC) etc.
Disadvantage of C
- It does not support object oriented programming(oops).
- It is a platform dependent language.
- It is a case sensitive language.
- It does not support database directly.
- It is not secure due to pointer.
Application of C
- It is mainly used to develop system software such as operating system compiler linker loader etc
- It is also used to develop application software such as school management system Supermarket.
- It is also used to develop game programming.
Tokens
Tokens are the smallest unit/elements that are used to create a program there are some tokens in C.
Character set
|
Constant
|
Variable
|
Keywords
|
Identifier
|
Data type
|
Escape sequence
|
Comment
|
Operator &
|
Expression
|
*Character set
It represent different type of set of character.
a) Alphabet-- A to Z ,a to z.
b) Digit -- 0-9
c) Special character:-
,
|
<
|
>
|
.
|
_
|
(
|
)
|
;
|
$
|
:
|
%
|
[
|
]
|
#
|
?
|
'
|
&
|
{
|
}
|
"
|
^
|
!
|
*
|
/
|
|
|
-
|
\
|
~
|
+
|
* Constant
Constant is a fixed value that cannot be changed during execution of program.
It is also known as literal.
Ex:- 10,10.5 "cimage" 'p'
#Types of constant
There are three types of constant.
- Numeric Constant.
- String constant
- Character set constant
*Numeric constant is two type.
Integer(10,100,45) and Real/Float(10.5,20.5).
*String constant
String is a collection of zero ,one and more character that are enclosed within double quote string is always terminated with the null character(\0).
It represent ending of character in string.
Ex:-"cimage" --|c|i|m|a|g|e|\0|
1 2 3 4 5 6 7 index value.
*Character constant
It represent only single character that is enclosed within single quote.
Ex:- 'a' 'A' '@' 'ab'.
*Variable
Variable is a memory location that is used to store constant value according to the specified data type It's value can be changed during execution of program.
a=10 b=10.5 nm="cimage".
ch|variable| = 's'|constant|
There are two types of variable.
- Local variable
- Global variable
Local variables:- Those variable that are declared within function called local variable.
It's provides local accessibility it means local variable cannot be accessed outside of function.
Global variable:- Those variable that are declared outside of function call Global variable it provides Global accessibility it means this variable can be accessed outside function and more than one function.
*Operators
Operator is a special symbol that performs operation on operands.
Eg:-- |10|+|20| 10,20=operands , |+|=Operator
#There are some operator:-
Arithmetic operator||Relational operator||Logical operator||Assignment operator
Compound assignment operator||Increment operator||Decrement operator||Comma operator
Size of operator||Bitwise operator||Unary operator ||Binary operator||Ternary operator
Note:-
Eg:-
Eg:-
Sizeof() operator:-
Unary operator:-
Eg:-- |10|+|20| 10,20=operands , |+|=Operator
#There are some operator:-
Compound assignment operator||Increment operator||Decrement operator||Comma operator
Size of operator||Bitwise operator||Unary operator ||Binary operator||Ternary operator
Arithmetic operator:-
This operator is used to perform arithmetic operations such as addition,subtraction multiplication etc.
+ | Adds two operands. | A + B = 30 |
− | Subtracts second operand from the first. | A − B = -10 |
* | Multiplies both operands. | A * B = 200 |
/ | Divides numerator by de-numerator. | B / A = 2 |
% | Modulus Operator and remainder of after an integer division. | B % A = 0 |
++ | Increment operator increases the integer value by one. | A++ = 11 |
-- | Decrement operator decreases the integer value by one. | A-- = 9 |
10.2%2.3=? X (error) Does not Support.
- Real time operand cannot be used with modulo division.
- The sign of remainder depends on only the sign of first operand
- If the value of first operand is less than the value of second operand then modulo division returns the value of first operand.
Relational operator:-
This operator is used to establish a relationship between two operands.
In other words it is used to compare between two value so it is also known as comparison operator. its main objective is to create condition in this case it returns Boolean value such as true or false if condition is true then it return 1 otherwise return 0.
== | Checks if the values of two operands are equal or not. If yes, then the condition becomes true. | (A == B) is not true. |
!= | Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. | (A != B) is true. |
> | Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. | (A <= B) is true. |
20 > =20 = 1
4 ! = 4 = 0
30 > 40 = 0
4 == 5 = 0
30 > 20 = 1
Logical operator:-
This operator is used to combined more than one condition.it also returns Boolean values such as 0 and 1.
&& | Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. | (A && B) is false. |
|| | Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. | !(A && B) is true. |
10 > 20 && 4! = 5 &&3 > 2 ------ 0
20 >= 20 && 4 > 3 ---1
30 > 20 || 40 ! = 40 ----1
! (40 > 50 ) -----1
! (30 > 20 && 4! =5 ) ----0
Assignment operator:-
This operator is used to assign value in a variable.
Eg:-
a=10
b=52.2=14=c45;
Compound Assignment operator:-
When arithmetic operator is used with assignment operator called compound assignment operator. it is also known as shortcut assignment operator.
When arithmetic operator is used with assignment operator called compound assignment operator. it is also known as shortcut assignment operator.
= | Simple assignment operator. Assigns values from right side operands to left side operand | C = A + B will assign the value of A + B to C |
+= | Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. | C += A is equivalent to C = C + A |
-= | Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. | C -= A is equivalent to C = C - A |
*= | Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. | C *= A is equivalent to C = C * A |
/= | Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. | C /= A is equivalent to C = C / A |
%= | Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. | C %= A is equivalent to C = C % A |
<<= | Left shift AND assignment operator. | C <<= 2 is same as C = C << 2 |
>>= | Right shift AND assignment operator. | C >>= 2 is same as C = C >> 2 |
&= | Bitwise AND assignment operator. | C &= 2 is same as C = C & 2 |
^= | Bitwise exclusive OR and assignment operator. | C ^= 2 is same as C = C ^ 2 |
|= | Bitwise inclusive OR and assignment operator. | C |= 2 is same as C = C | 2 |
This operator returns the size of datatype in byte.
sizeof(datatype).
sizeof(int) =2
sizeof(float) 4.
Bitwise Operator:-
This operator is used to perform bit operation in 0 and 1 format.
It is used in low level programming .
#There are two types of bitwise operator
- Logical bitwise operator
- Shift bitwise operator
Logical Bitwise Operator:-
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is as follows −
p | q | p & q | p | q | p ^ q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
Assume A = 60 and B = 13 in binary format, they will be as follows −
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
#Shift Bitwise operator:-
& | Binary AND Operator copies a bit to the result if it exists in both operands. | (A & B) = 12, i.e., 0000 1100 |
| | Binary OR Operator copies a bit if it exists in either operand. | (A | B) = 61, i.e., 0011 1101 |
^ | Binary XOR Operator copies the bit if it is set in one operand but not both. | (A ^ B) = 49, i.e., 0011 0001 |
~ | Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. | (~A ) = -61, i.e,. 1100 0011 in 2's complement form. |
<< | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. | A << 2 = 240 i.e., 1111 0000 |
>> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | A >> 2 = 15 i.e., 0000 1111 |
Those operator that are used with only single operand called unary operator.
Eg:- a++,b--.
Binary operator:-
Those operator that are used with two operands called Binary operator.
Ternary Operator:-This Operator is used to check small condition.In this case condition is checked if condition is true then true part will execute otherwise false part will execute. so it is also known as conditional operator. It is said to be ternary because it is used with three operands such as true part, false part and condition.
(?:) It represent
(Condition ? True part : False part)
Ex:-(n%2==0 ? "Even" : "Odd")
(n>0 ? "Positive" : "Negative")
Keywords:-
Data type:-
Escape Sequence:-
Identifier:-
Comment:-
Delimeter:-
Format Specifier:-
Structure of C program:-
Input/Output function:-
Control Statement:-
Array:-
String Handling:-
Function:-
Pointer:-
Structure:-
Recursive Function:-
Ternary Operator:-This Operator is used to check small condition.In this case condition is checked if condition is true then true part will execute otherwise false part will execute. so it is also known as conditional operator. It is said to be ternary because it is used with three operands such as true part, false part and condition.
(?:) It represent
(Condition ? True part : False part)
Ex:-(n%2==0 ? "Even" : "Odd")
(n>0 ? "Positive" : "Negative")
Keywords:-
Data type:-
Escape Sequence:-
Identifier:-
Comment:-
Delimeter:-
Format Specifier:-
Structure of C program:-
Input/Output function:-
Control Statement:-
Array:-
String Handling:-
Function:-
Pointer:-
Structure:-
Recursive Function:-
No comments:
Post a Comment