+ All Categories
Home > Documents > C language training in Noida

C language training in Noida

Date post: 12-Aug-2015
Category:
Upload: kumarrahul09
View: 28 times
Download: 0 times
Share this document with a friend
40
C Language WELCOME IN THE REATIVE WORLD OF C LANGUAGE
Transcript
Page 1: C language training in Noida

C LanguageWELCOME IN THE REATIVE WORLD OF C LANGUAGE

Page 2: C language training in Noida

Introduction to C Language

Denis Ritchie modified B language & implement at bell laboratories in 1972. The new language thus formed is named C. C was developed along with UNIX operating system so it is strongly associated with UNIX. These days C is running under a number of operating system including MS-DOS.

Page 3: C language training in Noida

Importance of C

•C has many set of built in functions and operators can be used to write any complex program.•C is suitable for writing both system software and business packages because C compiler combines the capabilities of an assembly language with the features of a high level language.•C is highly portable language.

Page 4: C language training in Noida

• C program is basically a collection of functions that are supported by the C library. The programming task become simple with the availability of a large number of functions.• C language is well suited for structured

programming. The structure of function modules or blocks makes program debugging, testing & maintenance easier.

Page 5: C language training in Noida

Format of C Program

main( ) Function Name{ Starting of Program

---------------------------- Program Statement--------------

} End of Program

Page 6: C language training in Noida

Basic Structure of C ProgramDocumentation SectionLink SectionDefinition SectionGlobal Declaration SectionMain ( ) function Section{

Declaration PartExecution Part

}

Sub Program SectionFunction 1Function 2….…Function m

User Defined Function

Page 7: C language training in Noida

Executing a ‘C’ Program

A series of Steps will be involved to execute a C program.

1. Creating the Program2. Compiling the Program3. Linking the Program4. Executing the Program

Page 8: C language training in Noida

Creating the Program

The program must be entered into a file. The file is created with the help of a text editor. Any corrections in the program are done under the editor. When the editing is over, the file is saved on disk. The file is saved on disk. The file name can consist of letters, digits and special characters, followed by a dot and a letter c. The program that is entered into the file is known as the source program, since it represent the original form of the program.

Page 9: C language training in Noida

Compiling the Program

The source program instructions are translated into a form that is suitable for execution by the computer. After examining each instruction about its correctness the translation is done. It every thing is alright, the compilation proceeds silently and the translated program is stored on another file with the name with extension of o i.e. (.o) which is known as object code.

Page 10: C language training in Noida

Linking the Program

Linking is the process of putting together other program files and functions that are required by the program. The programs will be linked with functions that are needed from the C library. Compilation process list out the mistakes in the syntax and semantics of the language.

Page 11: C language training in Noida

Executing the Program

While executing a program the instructions will be executed. The program may request for some data to be entered through the keyboard while executing. For the wrong program logic or data the program may not produce the desired result for which source program or data should be corrected. In case the source program is modified, the entire process of compiling, linking and executing the program should be repeated.

Page 12: C language training in Noida

Constants, Variables and Data Types

ConstantThe value that do not change during the execution of the program.1. Numeric constant:

i. Integer constantii. Real constant

2. Character constant: i. Single Character constantii. String constant

Page 13: C language training in Noida

Integer constant refers to a sequence of digits (0-9) also – or + signReal Constant refers to a number containing fractional parts. (floating point like 0.009)Character constant contains a single character enclosed in a pair or single quote marks. ‘5’, ‘x’, ‘;’A String constant may be letter, numbers, special characters and blank space enclosed in double quotes. “Name!”, “Well done”, “5+2”, “X”, “44”

Page 14: C language training in Noida

Variables

A variable is a data name that may be used to store a data value. Like constant this also remain unchanged during the execution of a program but a variable may take different values a different times during execution.Keyword, Special character and blank spaces are not valid variable name but under score ( _ ) is valid.

Page 15: C language training in Noida

Data types

C is rich in data type. The variety of data types available allow the programmer to select the type appropriate to the needs of the application as well as machine. C support 4 class of data type.1.Primary or fundamental data type2.User defined data type3.Derived data type4.Empty data set

Page 16: C language training in Noida

Primary Data Type

1. IntegerSigned Type Unsigned TypeInt (16 bit)Unsigned int (16 bit)Short int (8 bit) Unsigned short int (8 bit)Long int (32 bit) Unsigned long int (32 bit)

2. Character 3. Floating Point ValueSigned char (8 bit) Float (32 bit)Unsigned char (8 bit) double (64 bit)

long double (80 bit)

Page 17: C language training in Noida

Data Type RangeChar -128 to 127Int -32,768 to 32767Float 3.4 e-38 to 3.4e +38Double 1.7 e-308 to 1.7 e+308Unsigned char 0 to 255Unsigned int0 to 65535Short int -128 to 127Unsigned Short int 0 to 255Long int -2,147,483,648 to 2,147,483,647Unsigned int0 to 4,294,967,295Float 3.4E-38 to 3.4E+38Double 1.7E-308 to 1.7E+308Long Double3.4E-4932 to 1.1E+4932

Page 18: C language training in Noida

Data Types:

In a program we use the following basic data types:a) Integers: An integer is a basic data type which

contains discrete numbers like 1,2,4, 17, etc. An integer data can not be in fraction or exponent. Normally 2 byte is assigned for integer.

b) Characters: Character data type contain printable alpha-numeric characters as well as special characters as #, @, %, etc. Normally character is assigned by 1 byte.

Page 19: C language training in Noida

c) Real: Real data type can contain any numeric value that may be signed or unsigned, fractions, exponential. Eg: 7.0, 4.9986, 3.0E-4 etc.The number of digits before and after the decimal is fixed in fixed point representation of Real number.There is no fixed number of digits before and after the decimal point in floating point representation of real number. Here the decimal point can float.The amount of storage for double precision numbers are twice than the single precision floating point numbers.

Page 20: C language training in Noida

Logical or Boolean Data Type

Logical data type is useful to check the conditions inside the program. This data type contain only 2 type of value i.e. True or False. But this is not supported by all programming language.

Page 21: C language training in Noida

Data Structures

A Data structures is an organized grouping of data items treated as unit. They can be also called as complex data type:

1) Array: An array is a collection of same type of elements. The individual data items in an array are called as its element. Elements may be basic data types like integer, float, character or other data structures too.

Page 22: C language training in Noida

Each space in array is given an index number which is used to access each individual value, which is stored in each array element.Eg:

An array is of 1- dimensional or 2 dimensional even more as well.

Page 23: C language training in Noida

String

String is the one-dimensional array of characters. Part of string is called sub string. If the string is of fixed length then for data storage fixed number of character places will be available. The data will be provided just the needed number of spaces in variable - length strings.

Page 24: C language training in Noida

Character Set

The characters that can be used to form words, number and expression depend upon the computer on the program is run. The characters in c are grouped into1. letter- A-Z, a-z2. digits- 0-93. special character -, ; : ? \ / !~# $ % ^ & * ( ) - + | { } [ ]4. white space - Blank space, new line horizontal tab.

Page 25: C language training in Noida

Trigraph CharactersIf same characters are not available in keyboard they are supplied in the program by combining other characters ?? = # number sign ?? ( [ ?? ) ] ??< { ?? > } ?? ! ! veatical bar ?? / \ ?? ’ ^ ?? - ~

Page 26: C language training in Noida

C Tokens

In C, smallest individual units are known as c token 6 types Keyword float while string “ABC” “Year” Identifier main amount special symbol

[ ] { } Constant -15.5,100 Operators + - , * ,

Page 27: C language training in Noida

Keyword and IdentifierIdentifier refer to the name of variables, functions & array. These are user defined names and consist of a sequence of letters and digits, with a letter as a first character. Both upper & lower case permitted. All keywords have fixed meanings & they cannot be changes. They are basic building block of a program statement. Written in lower case.Eg :- auto, break, case, char, const, continue, default, do, double, else enum – extern, float, foe, goto, if, int, long, return, short signed size of, static, struct, switch, typedef, union, unsigned, void volatile, while. Constant < Num < int / real < char < single character / string

Page 28: C language training in Noida

Declaration of variable Declaration must be done before their use in program. Declaration of variable does two things.1. It tells the complier what the variable name is.2. It specifies what type of data the variable will hold.

Primary type declarationVariable can be used to store a value of any data. Data_type var1, var2, var3, ........., varN;In place of data_type particular keywords is used. Variables are separately by comma and ended with semicolon. Eg;- float x, y; long int amount ; unsigned n; int roll;double deviation; Short clas; short int Roll; char C ; long students;

If the specifier is without basic data type then it will be treated as int.

Page 29: C language training in Noida

typedef

“type identifier” allows user to define an identifier that would represent an existing data type.Eg:- typedef type identifier; typedef int units;Later on it can be used as. units batch1, batch2;

Page 30: C language training in Noida

enumThe identifier is a user defined enumerated data type which can be used to declare variables that can have one of the values enclosed within the brace ( enumeration constant) enum identifier v1, v2, …. Vn ; then v1….vn will have of the values Value 1 value 2….. value n. v, = value 3 ; v7 = value 2Eg ;- enum day {Monday, Tuesday, ….., Sunday};enum day week_st , week_end;week_st = Monday; week_end = Friday;

Page 31: C language training in Noida

Declaring a variable as constant const int class_size = 40; Declaring a variable as volatile volatile int data; volatile int location = 100; Reading data form keyboard scanf(“control string", &variable1, &variable2,…);

Page 32: C language training in Noida

Operator and expression An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. They are the part of mathematical or logical expression. They are:1. Arithmetic operator - +, - , * , / , % (modulo division)

2. Relational operator :- used for the comparison < , <= , >= ,= = , !=

3. Logical operator :- used to test more then one condition & make decisions. && - logical and if ( age > 25 && salary < 5000) , || - logical or if ( num <0 || num > 100)

Page 33: C language training in Noida

4. Assignment operator :- used to assign the result of an expression to a variable. variable operator = expression

x+ = 1 x = x + 1 x - = 1 x = x – 1 x* = n + 1 x = x * (n +1) x/= n +1 x = x/( n +1) x % = b x = x % b (right to left)

Page 34: C language training in Noida

5. Increment and decrement operators++ m or m++ - - m or m - -++ m is equivalent to m = m+1 ; (or m+ = 1;)If m = 5; and y = ++m; then value of y and m would be 6Prefix operator first adds 1 to the operator and then the result is assigned to the variable on left.

If m = 5; and y = m++; then value of y would be 5 & m would be 6Postfix operator first assigns the value of the variable on the left and then increments the operand.

Page 35: C language training in Noida

6. Conditional operator Exp1? Exp2: Exp 3;First exp1 is evaluated, if exp1 is non zero exp2 will be evaluated. If exp1 is false exp3 will be evaluated.If a =10; b = 15 ; then for x = ( a > b ) ?a :b;if ( a > b)x = a ;else x =b;

Page 36: C language training in Noida

Automatic type conversion

If the operands are of different types, the ‘lower’ type is automatically converted to the ‘higher’ type before operation proceeds. The result is of higher type.

Order – long double, double, float, unsigned long int, unsigned int.

Page 37: C language training in Noida

Casting a value

If we want to force a type conversion in a way that is different form the automatic conversion.( type_name ) expressionHere the type_name can be standard c data type and expression can be constant, variable or an expression.eg:- x=(int)7.5 , b=(double)x/y z=(int)(x+y) w=(int)p+q

Page 38: C language training in Noida

Some useful math functionsTo use math functions a header file math.h should be included.Function Meaningtan(x) - tangent of xsinh(x) - hyperbolic sin of xceil(x) - x rounded up to the nearest integer exp(x) - e to the power x (ex)fabs(x) - absolute value of xfloor(x) - x rounded down to the nearest integer fmod(x,y) - remainder of x/ylog(x) - natural log of x, x>0log10(x) - base 10 log of x, x>0pow (x,y) - x to the power y (xy)sqrt(x) - square root of x , x >=0

Page 39: C language training in Noida

Backslash Character Constants

Backslash Character constants are used in output functions.‘\a’ Audible Alert ‘\’’ Single Quote‘\b’ Back Space ‘\”’ Double Quote‘\n’ New Line ‘\?’ Question Mark‘\t’ Horizontal Tab ‘\\’ Back Slash‘\v’ Vertical Tab ‘\0’ Null

Page 40: C language training in Noida

CETPA Roorkee#200, Purvawali, 2nd Floor(Opp. Railway Ticket Agency)Railway Road, Ganeshpur, Roorkee - 247667 Contact Us: +91-9219602769, 01332-270218 Fax - 1332 - 274960

CETPA NoidaD-58, Sector-2, Red FM Lane, Noida -201301, Uttar Pradesh Contact Us: 0120-3839555, +91-9212172602

CETPA Lucknow#401 A, 4th Floor, Lekhraj Khazana,Faizabad Road , Indira Nagar,Lucknow - 226016 Uttar Pradesh Contact: +91-9258017974, 0522-6590802

CETPA Dehradun105, Mohit Vihar, Near Kamla Palace,GMS Road, Dehradun-248001,UKContact: +91-9219602771, 0135-6006070


Recommended