• No results found

C language Material

N/A
N/A
Protected

Academic year: 2021

Share "C language Material"

Copied!
26
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

1

COMPUTER TECH

Hardware tech

Software Tech

Applications System Software

Language

GPL Progamming Language {PL} Instructions Programmes Software

OVER VIEW

(3)

BASIC DEFINITIONS

Operating System : It is a set of programmes which act as an interface between user and hardware as well as which provides an environment to execute the user command

OS is acting as manager for both software and hardware resources

Package : It is a predefined programme designed by somebody else and used by us

Language : Which are used to communicate with system inorder to construct the programming structure Why C is ?

*It supports to develop wide range of programmes

*Doesnot require to write lengthy programmes for small calculations

*The programmes are executing with high efficiency

*C programmes are portable and transportable or machine independent

(4)

HISTORY OF LANGUAGES

*COBOL (COmmon Bussiness Oriented Language) was the first language introduced.The name itself suggests that this language was for bussiness purpose

**So this is not useful for Engineering purpose

*FORTRAN (FORmula TRANslation) this was the second language after COBOL .This is very useful in Eng.. purposes

**This is not useful for Bussiness Purposes

*C.P.L (Common Programming Language) this was the language that was introduced to fill the drawbacks of first two.This is useful for both bussiness and Engineering purposes

**But this language requires a lot steps to execute a small work

*B.C.P.L (Basic Common Programming Language) this language can execute work's in verl less steps

**But This language was found not to execute that effectively (in terms of speed)

*B-Language was developed at Bells lab and this was found to satisfy the drawbacks of B.C.P.L and the letter B was take from B.C.P.L

**But this was a machine dependent language(which means In Olden days there were 3 types of computer's Mini,Micro,Mainframe.The programme

(5)

**Hence after all the above draw backs have been filled

a machine independent language was introduced by

Dennis Ritchie at "AT&T " in 1970 but it became popular

after 2 years i.e 1972

**C language is the language:

"C is a high level language

"Which is useful for bussiness as well as Eng. purpose

"It executes works in less steps and very fast

"This is a Machine Independent language

"It is portable and transportable

(6)

TYPES OF LANGUAGES

MACHINE LANGUAGE

Assembly language

HIGHLEVEL LANGUAGE

This is the language

that is understood by machine.Binary Digits (0 & 1) are used in this

language

This is also called as

Lowlevel language Binary Language

This language includes Binary digits and even symbols (+,-,*)

This is the language which can be

understood by the programmer

(a-z,0-9 .!@$...)

TRANSLATOR

The code written using high lvl lang is called source code

The code written using this lang is called object code

SOURCE CODE OBJECT

(7)

TRANSLATOR

Translators are those which are used to transulate the source code to object code (where source code is code written by us in high level language where as object code is nothing but the code which is

machine understandable

TRANSLATOR

INTERPRETERS

COMPILERS

Interpreters are used to transulate source code to object code consequently (step by step) .If at all any errors are occured the programme execution will stops over there till it is error free

The Compilers are used to transulate source code to object code in a single attemptif at all any

errord are occured they are isolated on seperate screen

(8)

1. C-TOKENS

*A taken is nothing but the smallest individual component in the programme to understand the C-Language we need to aware os the following tokens.

i) Character set ii) Variables

iii) Data types iv) Operators v) Identifiers vi) Keywords #Character set :

The C lang can understand only

ASCII(American Standard Code for Information Interchange) Character set. Whose range is from 0 to 255 which includes A-Z,a-z,0-9,Special Characters A-Z (65 to 90) a-z (97 to 122) 0-9 (48 to 57) Space bar (32) Enter Key ( 13) Escape (27)

(9)

#Variable : A space to stor data while execution of

programme (Simple definition)

It is a memory allocation which enables you to store the data temporarily during the programme

execution.In another words a space to store data Syn:<datatype> <variable>

##Data types : It represents the type of value s to be

presented in the specified memoery

●Integer(Signed Integer) : It allows you to store a number without decimal(sequence of didgits)

→It will take 2 bytes of space in the memory →Its range is -32768 to 32767

→It represents with "int"

Note : By default Integer is a signed integer Ex: int studentno; or signed int studentno;

●Unsigned Integer : Allows you to store a number without decimal

→It will take 2 bytes of space in memory →Its range is from 0 to 65535

→It represent's with "unsigned int"

Ex ; unsigned int HallTicketNo; Values :12u,234u,etc

Here u makes them as Unsigned Interger as system take only "12" as a Integer(Signed Inter)

(10)

Long Integer

: It allows you to store a number without decimal →It will take 4 bytes of space

→It is represented with "long int" whose range is from -2,147,483,648 to 2,147,483,647

Eg ; lont int oldbalance; Values:5456l,-2346l

●Unsigned Long ; Allows you to store a number without decimal

→Will take 4 bytes of space in memory →Its range is from 0 to 4,294,967,295

Ex; unsigned long oldblance; Values :45678lu,234567lu

●Float:It allows you to store the real numbers i.e Scientific

values,Exponential values

→It will take 4 bytes of space in the memory whose range is from ±3.4e^±38

→It is represent's with "float"

Ex:3.14f,4.3445f,27.000000(6 decimal places only)

●DOUBLE: It allows you to store a number with decimal

→It will take 8 byte space in the memory whose range is 1.7e^±308 Ex:3.14lf

●LONG DOUBLE : It allows you to store a number with decimal it will take

10bytes space in memory . →Its range is 3.4e^±4932

(11)

CHARACTER

>It is classified into two types Signed Character and Unsinged Character

>Both signed and Unsigned will take 1 byte space in the memory

>Range of unsigned character is 0 to 255 Range of Signed character is -128 to 127

Note: By default Character Data type will take 1 byte space in memory adn hence it will store only 1 character And if we need need more than one character then we need to specify the no.of characters in "[<number>]" besode data type

Ex ; char SName; <- This will allow to store only 1

charcter Ex: A,B,C,If we type "Ravi" It will take only "R"

(12)

Excercise 1:

1.Declare the varaible to store Student Name,Hall Tick No, S City

Sol. unsigned int HallTicketNo; char SName[30];

char SCity;

2.Declare the varaiable to store Employ Name,Job,Salary, date of joining.

Sol. char EName[30]; char Job[30]; long int salary; char date[10]

(13)

OPERATORS

Operators are those which are used to perform the operation on the operants.Usually operators are of two types :

1)unary operators 2)Binary Operators

>An Operator which is used to perform the operation on single operant is called as Unary Operator

Ex; X++

>Where as which performs the operation over two operants are called Binary Operator

Ex: X+Y TYPES OF OPERATORS ARTHIMETIC OPERATOR RELATIONAL OPERATOR LOGICAL OPERATOR ASSIGNMENT OPERATOR CONDITIONAL OPERATOR

INCRIMENT OR DECREMENT OPERATOR

SIZE OF OPERATOR

(14)

OPERATION MEANING ACTION RESULT a= 10 b= 5 + ADD a+b 15 - SUB a-b 5 x MUL axb 50 / DIV a/b 2 % MOD a%b 0

Arthemaitc Operators : which are used to perform all arthematic operations BODMAS ORDER ; ()/x+-a=2 b=3 c=5 d = a+bxc 17 d=(a+b)xc 25 int X=5;float y;

y=5/2; Exp output ;2.5 Act output 2.0 int/int =>int 5/2 = 2

int/float =>float 5/0.2f=2.5 float/int =>float 5.0f/2=2.5 float/float =>float 5.0f/2.0f=2.5

But priority in C Lang will not be as BODMAS here is the order of priority

Ist Priority => /x% IInd Priority => +-IIIrd Priority => =

(15)

OPERATION MEANING ACTION RESULT a= 10 b= 5 > GT a>b 1 < LT a<b 0 >= GT Eq a>=b 1 <= LT Eq a<=b 0 == Equal a==b 0 != Not Eq a!=b 1

Relational Operator : Which are used to check the relation among Operators.It will return values in BOOLEAN values (0 for false 1 for true)

The Evaluation will be from left to right

a=10 b=20 Ex; c=a>b (0) Left to right ---> ---c=2<3!=10 Step1 1!=10 Step2 1 Step3

(16)

---EXP1 AND EXP2 ACTION RESULT

(a>b)0 AND (a>c)0 (a>b)&&(a>c) 0 (b>a)1 AND (b>c)0 (b>a)&&(b>c) 0 (c>a)1 AND (c>b)1 (c>a)&&(c>b) 1

a = 10;b =20;c=30;

EXP1 OR EXP2 ACTION RESULT

(a>b)0 OR (a>c)0 (a>b)l l(a>c) 0 (b>a)1 OR (b>c)0 (b>a)l l(b>c) 1 (c>a)1 OR (c>b)1 (c>a)l l(c>b) 1

a = 10;b =20;c=30;

LOGICAL OPERATOR ;

=>Enables you to work with more than one condition =>AND,OR,NOT are Logical Operators

AND=> When all the conditions are true then only we will get true and in all other cases false

Symbol :- &&

OR => When all conditions are false then only we will get false or else true

(17)

Examples:

Case 1 : (a>b)&&(a>c) l l (c==c&&a!=a) 0 && 0 l l 1 && 0 0 l l 0 0 Case2 : (2+3!=5)&&3>2)&&(3+2<5 l l 5+5<10) 0 & 1 && 0 l l 0 0 && 0 0 Assignment Operator :

=>Used to assign a value or an expression .It is always from (right to left)

Symbol :- ==

Syn :- <data type> <variable name>

x=10 int x;Variable decleration y=20 x = 100; initial

z =30(x+y) int x=100 -> variable decleartion cum Initial int x=y=z=30 ; Multi declerational cum initial

(18)

Conditional Operator : Which will check the initial condition initially.If the condition is true it will execute logical true (or) If the conidition is flase it will execute logical falselogical false.It is also known as Terminary Operator

Symbol :- "? and :"

Syn : (<condition>)?LOGICAL_TRUE : LOGICAL_FALSE a=10 b=5 Ex:Marks = 67 (Marks>34)?printf("PASS") : printf("FAIL"); or (Marks<34)?printf("FAIL") : printf("PASS") Ex2: a=2 b=3 c;

(a<b)?c=a+b : c=a*b; //invalid

c=(a<b)?a+b:a*b; // valid Output=5

Increment or decrement operators :

>Increment operator used for increase by a value >>Symbol : ++

Ex; y+1 or y++

>Decrement operator used for decrease by a value >>Symbol :

(19)

y--Both Increment or Decrement operators are classified into 2 catogaries

1)Preincriment or Predecrement 2)Postincriment or Postdecrement

In preincriment or Predecrement values of variable will be increased or decreased by 1 before initilisation where as postincrment or post decrement values of variable will be increased or decreased by one after initilisation.

Increment Pre inc : ++x Post inc : x++ Decrement Pre Decr : --x Post Decre : x y z 10 20 30 y=++x 11 11 30 x y z 10 20 30 y=x++ 11 10 30

(20)

STEP OPERATION x y z 10 20 30 Step1 y=++x 11 11 30 Step2 x=--y 10 10 30 Step3 z=++x 11 10 11 Step4 y=x++ 12 11 11 x y x y 10 20 10 20 y=++x 11 11 y=x++ 11 10

Hence clearly we can see that these both are different The case in which they both give same result is as below : x x

10 10 x++ 11 ++x 11 Only in this case they are same

Example:

Note;Here every step is written from its above step

which step 1 is from basic and step 2 is from step1 and so on

(21)

OPERATION ACTION

Mean

+= x+=10 x=x+10 -= y-=x y=y-x *= n*=m n=n*m /= n/=m n=n/m %= n%=m n=n%m

Sizeof Operator : Which returns size of the specified variable or a datatype Ex: int x; printf("%d",sizeof(x)): printf("%d",sizeof(float))://4 printf("%d",sizeof(clrscr()))://2 Compond operators:

=>It is combination of both arthematic and asiignment

operators it will work similar with arthematic operators also known as shortcut operators.

(22)

Identifier : A variable is nothing but space to store data where as an identifier is nothing but a name given to a space alternatively all the names which are designed by us for

programming conviency

Limitations :

1)An identifier must begin with an alphabhet 2)It length do not exceed32 characters

3)It may be in upper case or lower case or middle case 4)It may have a special character is an "_" Underscore Note : Two consequetive underscore should not be used. 5)It may have digits

6)It must not be C Land related keyword

Keywords :

=>Keywords are nothing but reserved words

=>The meaning of words is already defined to the compiler =>Every keyword is having its own importance

(23)

asm break case cdecl char const continue default do double else enum extern far float for goto huge if int interrupt long near pasis register return short signed sizeof static struct switched typedef union unsigned void volatile while

(24)

/*comment Section*/ File inclusions

Pre processor directives Global Declarations void main () { [local variables] Statement(s); =========== }

[<return type>] <functionname><[list of arguments]> [local variables];

statement(s);

[return <variable/exp/value>];

(25)

COMMENT SECTION :

=>In comment section we can write anything related to the programme we can write the comment section.

=>we can write the comment section any wher in programme and any no.of times whatever the statements which are taken in

between /* and */ those lines are ignored by the compiler

=>comment witin comment is not supported in the C-Complier

FILE INCLUSIONS :

=>A library is nothing but collection of functions

=>In C-Language we have varies libraries for performing various operations

=>while working with any function in programme it is

recommended to use corresponding library name as a file inclusion

Ex;

C-language

Stdio.h String.h Conio.h

printf() scanf() strlen() strupr()

...

Ex: /*To print a msg*/ #include <stdio.h> void main() { printf("This is C Notes) } File Inclusion

(26)

INPUT AND OUTPUT FUNCTIONS :

*Input functions are used to take the values from input device and assign to specific variables

Eg: scanf()

where f stands for format

*Output functions are used to read the values from variables and display it on the screen

Eg:printf()

References

Related documents

A series of tests of HTS tapes produced by SJTU and AMSC are carried out to test the tape characteristics and to prove the current limiting ability of supercon- ducting

The criticalcurrent of the double-insert YBCO tapes is 500 A, so 10 modulesare needed to meet the requirement of 5 kA critical current.The structure of a single current

As these results show, a change in the terms of trade has opposite effects on the real wages of male and female workers whether considering the real wage either in terms of

The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify

Professor Muhanna has published numerous articles in scholarly journals, including Management Science, MIS Quarterly, Strategic Management Journal, Decision Sciences, the Journal

– Translate source code from high-level language to low- level language (object code or machine code). – Create an

The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify

The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify