Overview of c (2)

41
Overview of “C” 1 By Abhinav and Aayush

Transcript of Overview of c (2)

Page 1: Overview of c (2)

Overview of “C”

1By Abhinav and Aayush

Page 2: Overview of c (2)

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

Page 3: Overview of c (2)

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

Page 4: Overview of c (2)

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

Page 5: Overview of c (2)

(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

Page 6: Overview of c (2)

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

Page 7: Overview of c (2)

Constant

Constant

Numeric

Character

Symbolic

Black Slash

(1) Integer(2) Real

(1) Single Character(2) String

7

Eg.-“\n”

By Abhinav and Aayush

Page 8: Overview of c (2)

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

Page 9: Overview of c (2)

Data Types

Primitive Non-Primitive

Int char floatvoid pointer

Array EnumStruct

9By Abhinav and Aayush

Page 10: Overview of c (2)

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

Page 11: Overview of c (2)

Input

• scanf(“string”,&address_list_of_identifiers);

• identifier name=getchar();

• identifier name=getc(stdin);

• gets(identifier name);

11By Abhinav and Aayush

Page 12: Overview of c (2)

Output

Printf(“message string”);

Putchar(“a”);

putc(“a”);

puts(“identifier name”);

12By Abhinav and Aayush

Page 13: Overview of c (2)

Operator

Arithmetic

Assignment

Relation

Increment/Decrement

Conditional

Logical

Bitwise

Special

13By Abhinav and Aayush

Page 14: Overview of c (2)

Arithmetic Operators

+ Addition operator

- Subtraction operator

• Multiplication operator

/ Division operator

% Module operator

14By Abhinav and Aayush

Page 15: Overview of c (2)

Assignment Operators

Identifier A0p=constant value;

Ex-

Area=(base * height)/2;

Roll_no=14;

15By Abhinav and Aayush

Page 16: Overview of c (2)

Relational Operators

== Equal to

!= Not Equal to

> Greater than

< Less than

>= Greater than Equal to

<= Less than Equal to

16By Abhinav and Aayush

Page 17: Overview of c (2)

Increment and Decrement Operators

++identifier or identifier++

--identifier or identifier—

17By Abhinav and Aayush

Page 18: Overview of c (2)

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

Page 19: Overview of c (2)

Logical Operators

&& Logical AND

|| Logical Or

! Logical NOT

19By Abhinav and Aayush

Page 20: Overview of c (2)

Bitwise Operators

& Bitwise AND

| Bitwise OR

~ Bitwise NOT

^ Bitwise Exclusive OR

20By Abhinav and Aayush

Page 21: Overview of c (2)

Special Operators

• Category Symbol

• Sizeof sizeof()

• Pointer & , *

• Member Selection . , ->

21By Abhinav and Aayush

Page 22: Overview of c (2)

If Statement

if(test condition)

Action statement;

If-else Statementif(test condition)

{

True action statement;

}

else

{

False action statement;

}22By Abhinav and Aayush

Page 23: Overview of c (2)

Switch

Switch(expression)

{

Case v1:

Action block 1;

break;

-

-

Case value N :

Action block N;

Break;

Default :

Action block;

Break;

} 23By Abhinav and Aayush

Page 24: Overview of c (2)

For loop

For(initiailization; condition;increment)

{

Action block;

}

while loop

While(test condition)

Action block;24By Abhinav and Aayush

Page 25: Overview of c (2)

Do while

Do

{

Action block;

}

While(test condition);

25By Abhinav and Aayush

Page 26: Overview of c (2)

Goto

goto label;

26By Abhinav and Aayush

Page 27: Overview of c (2)

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

Page 28: Overview of c (2)

Steps of function

• Function declaration( above main function)

• Function call(in the main function)

• Function definition( below main function)

28By Abhinav and Aayush

Page 29: Overview of c (2)

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

Page 30: Overview of c (2)

Types of array

• Single-dimensional array

• Two-dimensional array

• Multi-dimensional array

30By Abhinav and Aayush

Page 31: Overview of c (2)

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

Page 32: Overview of c (2)

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

Page 33: Overview of c (2)

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

Page 34: Overview of c (2)

String

One or more character are called string.

Syntax

Data type string name[size];

Ex-

Char name[10];

34By Abhinav and Aayush

Page 35: Overview of c (2)

Type of string

• Strcat()-join two string

• Strcpy()-one string copy to another

• Strcmp()-comparison two strings.

• Strlen()-length

35By Abhinav and Aayush

Page 36: Overview of c (2)

Strcat()

S1=abc S2=def

S3=strcat(S1,S2);

abcdef

Strcpy()S1=abc S2=def

S3=strcpy(S1,S2);

def

36By Abhinav and Aayush

Page 37: Overview of c (2)

Strcmp()

S1=abc S2=xaz

S3=strcmp(S1,S2)

a

Strlen()S1=tbs

n=strlen(S1);

n=3

37By Abhinav and Aayush

Page 38: Overview of c (2)

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

Page 39: Overview of c (2)

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

Page 40: Overview of c (2)

40By Abhinav and Aayush

Page 41: Overview of c (2)

Thank You

41By Abhinav and Aayush