Overview of c (2)
-
Upload
aayush-patel -
Category
Documents
-
view
42 -
download
0
Transcript of Overview of c (2)
Overview of “C”
1By Abhinav and Aayush
History Of C Language
• The origin of C language dates back to 1972.
• Dennis M. Ritchie is the man who owns the credit of creating the C language.
• Although created in 1972, it was standardized in 1989 by ANSI(American National Standard Institute). It came to be known as ANSI C.
• Some of them have even provided an integrated development environment, more commonly known as IDE.
2By Abhinav and Aayush
Structure of a C program
Documention
File include section
Symbolic Constant Definition
Global Declaration
Main()
{
Declaration
Executable Statements
}
Function 1
{
Declaration
Executable Statement
}
Function N
Optional Section used for Decoumention and global declarations
Compulsory Section for all Executable C program
Optional Section used to write user defined functions
3By Abhinav and Aayush
Character set of C
• Letters(a To z and A To Z)
• Digits (0 ,1,2,3,4,5,6,7,8,9)
• White spaces(Blank space, Form feed, Horizontal tab, New line, vertical tab)
• Special Characters( & , ‘ * @ \ {} [] ^ : $ = ! / > # < - () % . + ? “ ; _ |)
4By Abhinav and Aayush
(Keyword)#include<stdio.h>
main()
{
int i_tot_cost, i_qty=12,i_cost=50;
clrscr();
i_tot_cost=i_qty*i_cost;
Printf(“Cost of %d items is %d”,i_qrt,i_cost);
return;
}
(Constant)
(Identifier)
(Operator)
(String)
(Special Character)
5By Abhinav and Aayush
Keyword
Auto double int stuct
Break else long switch
Case enum register typedef
Char extern return union
Const float short unsigned
Continue for signed void
Default goto sizeof volatile
Do if static while
6By Abhinav and Aayush
Constant
Constant
Numeric
Character
Symbolic
Black Slash
(1) Integer(2) Real
(1) Single Character(2) String
7
Eg.-“\n”
By Abhinav and Aayush
Back Slash Characters
Back Slash Characters ASCII Value
\0 0
\a 7
\b 8
\t 9
\n 10
\f 12
\* 34
8By Abhinav and Aayush
Data Types
Primitive Non-Primitive
Int char floatvoid pointer
Array EnumStruct
9By Abhinav and Aayush
Input and Output Functions
Formatted FunctionFunction Used for
Scanf Input
Printf Output
unformatted FunctionFunction Used for
Getchar() input
Gets() input
Getc() input
Putchar() output
Putc() output
Puts() output
10By Abhinav and Aayush
Input
• scanf(“string”,&address_list_of_identifiers);
• identifier name=getchar();
• identifier name=getc(stdin);
• gets(identifier name);
11By Abhinav and Aayush
Output
Printf(“message string”);
Putchar(“a”);
putc(“a”);
puts(“identifier name”);
12By Abhinav and Aayush
Operator
Arithmetic
Assignment
Relation
Increment/Decrement
Conditional
Logical
Bitwise
Special
13By Abhinav and Aayush
Arithmetic Operators
+ Addition operator
- Subtraction operator
• Multiplication operator
/ Division operator
% Module operator
14By Abhinav and Aayush
Assignment Operators
Identifier A0p=constant value;
Ex-
Area=(base * height)/2;
Roll_no=14;
15By Abhinav and Aayush
Relational Operators
== Equal to
!= Not Equal to
> Greater than
< Less than
>= Greater than Equal to
<= Less than Equal to
16By Abhinav and Aayush
Increment and Decrement Operators
++identifier or identifier++
--identifier or identifier—
17By Abhinav and Aayush
Condition
(condition) ? (true statement) : (false statement)
Ex-
i_minimum=(i_num1<=i_num2)?(i_num1):(i_num2);
Printf(“the min value of the two is %d”,i_minimum);
18By Abhinav and Aayush
Logical Operators
&& Logical AND
|| Logical Or
! Logical NOT
19By Abhinav and Aayush
Bitwise Operators
& Bitwise AND
| Bitwise OR
~ Bitwise NOT
^ Bitwise Exclusive OR
20By Abhinav and Aayush
Special Operators
• Category Symbol
• Sizeof sizeof()
• Pointer & , *
• Member Selection . , ->
21By Abhinav and Aayush
If Statement
if(test condition)
Action statement;
If-else Statementif(test condition)
{
True action statement;
}
else
{
False action statement;
}22By Abhinav and Aayush
Switch
Switch(expression)
{
Case v1:
Action block 1;
break;
-
-
Case value N :
Action block N;
Break;
Default :
Action block;
Break;
} 23By Abhinav and Aayush
For loop
For(initiailization; condition;increment)
{
Action block;
}
while loop
While(test condition)
Action block;24By Abhinav and Aayush
Do while
Do
{
Action block;
}
While(test condition);
25By Abhinav and Aayush
Goto
goto label;
26By Abhinav and Aayush
Types of function
• Function with no parameter and no return value
• Function with no parameter and return value
• Function with parameter and return value
• Function with parameter and no return value
27By Abhinav and Aayush
Steps of function
• Function declaration( above main function)
• Function call(in the main function)
• Function definition( below main function)
28By Abhinav and Aayush
Call by value
Function call time passing value it is called “call by value”.
C=add(a,b)
Call by referenceFunction call time passing address it is called
“call by reference”.
C=add(&a,&b)
29By Abhinav and Aayush
Types of array
• Single-dimensional array
• Two-dimensional array
• Multi-dimensional array
30By Abhinav and Aayush
Single-dimensional array
If an array has only one dimensional, it is call Single-dimensional array
Syntax-
Type arrayname[size];
Ex-
Int a[5];
31By Abhinav and Aayush
Two-dimensional array
If an array has only two dimensional, it is call two-dimensional array
Syntax-
Type arrayname[size] [size] [size];
Ex-
Int [5][5];
32By Abhinav and Aayush
Multi-dimensional array
If an array has two or more dimensional it is call multi-dimensional array
Syntax-
Type arrayname[size] [size] [size];
Exp-
Int [5][5][2];
33By Abhinav and Aayush
String
One or more character are called string.
Syntax
Data type string name[size];
Ex-
Char name[10];
34By Abhinav and Aayush
Type of string
• Strcat()-join two string
• Strcpy()-one string copy to another
• Strcmp()-comparison two strings.
• Strlen()-length
35By Abhinav and Aayush
Strcat()
S1=abc S2=def
S3=strcat(S1,S2);
abcdef
Strcpy()S1=abc S2=def
S3=strcpy(S1,S2);
def
36By Abhinav and Aayush
Strcmp()
S1=abc S2=xaz
S3=strcmp(S1,S2)
a
Strlen()S1=tbs
n=strlen(S1);
n=3
37By Abhinav and Aayush
Structure
• Structure is user define data type it is used to collection of deffertent data item in single location.
Syntax-
Struct structure name
{
Data item 1
--
--
}
38By Abhinav and Aayush
Union
Union are same to Structure. One different
between structure and union. Structure
member’s memory allocate every member but
union have only one member’s memory
allocate.
39By Abhinav and Aayush
40By Abhinav and Aayush
Thank You
41By Abhinav and Aayush