1 / 380

C Programming Language

C Programming Language. History of ‘C’. 1960. ALGOL. International Group. 1967. BCPL. Martin Richards. 1970. B. Ken Thompson. 1972. Traditional C. Dennits Ritchie. 1978. K & R C. Kernighan and Ritchie. 1989. ANSI C. ANSI Committee. 1990. ANSI / ISO C. ISO Committee.

Télécharger la présentation

C Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Programming Language

  2. History of ‘C’ 1960 ALGOL International Group 1967 BCPL Martin Richards 1970 B Ken Thompson 1972 Traditional C Dennits Ritchie 1978 K & R C Kernighan and Ritchie 1989 ANSI C ANSI Committee 1990 ANSI / ISO C ISO Committee

  3. Why are using ‘C’ • It is a Structured Programming Language • High – Level Language • Machine Independent Language • It allows software developers to develop programs without worrying about the hardware platforms where they will be implemented TYPES OF ‘C’ COMPILER 1. Borland ‘C’ Compiler 2. Turbo ‘C’ Compiler 3. Microsoft ‘C’ Compiler 4. ANSI ‘C’ Compiler

  4. Characteristics of C We briefly list some of C's characteristics that define the language • Small size • Extensive use of function calls • Loose typing -- unlike PASCAL • Structured language • Low level (Bitwise) programming readily available • Pointer implementation - extensive use of pointers for memory, array, structures and functions. • C has now become a widely used professional language for various reasons. • It has high-level constructs. • It can handle low-level activities. • It produces efficient programs. • It can be compiled on a variety of computers.

  5. Steps in Learning C Character set Files Data Structures Structures and Unions Algorithms Constants, variable And Data types Control statements Pointers Programs Functions Arrays

  6. C’S Program Structure Documentation section Preprocessor section Definition section Global declaration section main() { Declaration part; Executable part; } Sub program section { Body of the subprogram }

  7. C’s Character set

  8. C TOKENS C TOKENS Constants Strings -15.5 100 “ABC” “YEAR” Identifiers Operators main amount + - * / Keywords Special Symbols float while [ ] { }

  9. Program elements where Identifiers are used Variables Functions Arrays Function parameters Macros and macro parameters Type definitions Rules for Using Identifiers Only Letter, Digits and Underscore(_) 1st character should be letter or _ Both Upper/lower case can be used It can be of any length No space and Special symbol is used It cant be a keyword C’s Identifiers

  10. C’s keyword • Basic Building Block of the Program • These are the Reserved words • These word’s cant be changed

  11. Data Types • This are the type of the data that are going to access within the program.

  12. C’s Data types cont. The primary data types are further classified as below. Integers are the whole numbers, both positive and negative.

  13. C’s Data types cont. Float are the numbers which contain fractional parts, both Positive and Negative.

  14. C’s Data types cont. Char are the characters which contain alpha-numeric character. Characters are usually stored in 8 bits (one byte) of internal storage The void is the Null Data type.

  15. C’s Variables • A variable is a data name as well as identifier that may be used to store a data value. Rules for Naming the Variables • A variable can be of any combination of alphabets, digits and underscore. • The first character of the variable can’t be digits. • The length of the variable can’t be exceeded by 8.(ANSI C – 32 Character) • No commas, blanks or special symbol are allowed within a variable name. • Uppercase and lowercase are significant. That is, the variable Total is not the same as total or TOTAL. • It should not be a keyword. • White space is not allowed.

  16. C’s Variables cont.

  17. C’s Variables cont.

  18. C’s constant The item whose values can’t be changed during execution of program are called constants

  19. C’s constant Conti… Integer constant eg: roll_number = 12345; Real Constant eg: pi = 3.14; Decimal Constant Eg. 35 Octal constant Eg. 043 Hexadecimal constant Eg. 0x23 Single Precision Constant Double Precision Constant

  20. Rules for constructing Integer constants 1. An integer constant may be positive or negative (Default sign is positive). 2. An integer constant should not have a decimal point. 3. No commas and blank spaces are allowed in an integer constant. 4. An integer constant, should not use exponent e. The suffix u or U is used for denoting unsigned int constants, I or L is used for denoting long int constants, and s is used for denoting short int constants.

  21. Real Constants are often called as Floating – point constants. Real constants is classified as two types. 1. Fractional form. 2. Exponential form. Rules for constructing real constants (fractional form) 1. A real constant may be positive or negative (Default sign in positive 2. A real constant must have a decimal point. 3. No commas and blank spaces are allowed in a real constant. Example: 0.0001 -0.963 485.98 +123.456 727.01 0.987 -.8765 +001.05

  22. Rules for constructing Real Constants (Exponential Form) 1. The mantissa part and the exponential part should be separated by a letter e. 2. The mantissa part and the exponential part may be positive or negative (Default sign is positive) 3. The mantissa and the exponent part must have at least one digit. 4. No commas and blank spaces are allowed in a real constant. Example: +3.2e+5 3.4e5 -8.2e-5 -10.9e5 9.7e-10 0.0025e8

  23. Rules for constructing String Constants 1. A string constant may be a single alphabet or a digit, or a special character or sequence of alphabets or digits enclosed in double quotes. 2. Every string constant ends up with a NULL character, which is automatically assigned. Example: “w” “100” “Madhu” “ABC 123” “Good_Morning” “s1000” “219.71” “30-01-1978”

  24. C’ Delimiters Delimiters are the symbols, which has some syntactic meaning and has got significance.

  25. C’ Statements • Statement can be defined as set of declarations (or) sequence of action • All statements in ‘C’ ends with semicolon(;) except condition and • control statement

  26. C’ Statements

  27. Expression Statement 1. An Expression is a combination of constant, variables, operators, and function calls written in any form as per the syntax of the C language. 2. The values evaluated in these expressions can be stored in variables and used as a part for evaluating larger expressions. 3. They are evaluated using an assignment statement of the form. variable = expression; 4. For Example, age = 21; result = pow(2,2); simple_interest = (p * n * r) / 100;

  28. Compound Statements 1. A group of valid C expression statements placed within an opening flower brace ‘{‘ and closing flower brace ‘}’ is referred as a Compound Statements. 2. For Example, { X = (A + (B * 3) – C); Y = A + B * 3; Z = A * (B * 3 – C); } Control Statements 1. This statement normally executed sequentially as they appear in the program. 2. In some situations where we may have to change the order of execution of statements until some specified conditions are met. 3. The control statement alter the execution of statements depending upon the conditions specified inside the parenthesis. 4. For Example, if (a == b) if ((x < y) && (y > z)) { { -------- ----------- -------- ----------- } }

  29. ESCAPE SEQUENTIAL CHARACTER OR BACKSLASH CHARACTER CONSTANTS

  30. Operators An operator is a symbol that specifies an operation to be performed on the operands • Some operator needs two operands (binary) • Eg: a+b; ‘+’ is an operator and ‘a’ and ‘b’ are the operands • Some operator needs one operand (unary) • Eg: ++a; ‘++’ is an operator and a is the operand

  31. Types of Operators

  32. This operators help us to carryout basic arithmetic operations such addition, subtraction, multiplication, division Arithmetic Operators

  33. This are used to compare two or more operands. Operands can be variables, constants or expression. eg: comparison of two marks or two values. Relational Operator

  34. This operators are used to combine the results of two or more conditions. LogicalOperator

  35. Assignment Operator • This are used to assign a value or an expression or a variable to another variable • eg: a = 10; n1 = 20; Syntax: identifier = expression; • Compound Assignment This operator are used to assign a value to a variable in order to assign a new value to a variable after performing a specified operation. eg: a+=10,n1-=20; • Nested Assignment (Multiple) This operator are used to assign a single value to multiple variables eg: a=b=c=d=e=10;

  36. List of Shorthand or Compound Assignment Operator

  37. C provide two operator for incrementing a value or decrementing a value a) ++ Increment operator (adds one to the variable) b) -- Decrement operator (Minus one to the variable) eg: a++ (if a= 10 then the output would be 11) Increment and Decrement operator

  38. Increment and Decrement operator Conti… If the value of the operand x is 3 then the various expressions and their results are The pre – increment operation (++X) increments x by 1 and then assign the value to x. The post – increment operation (X++) assigns the value to x and then increments 1. The pre-decrement operation ( --X) decrements 1 and then assigns to x. The post – decrement operation (x--) assigns the value to x and then decrements 1. These operators are usually very efficient, but causes confusion if your try to use too many evaluations in a single statement.

  39. It is used check the condition and execute the statement depending upon the condition Conditional Operator

  40. Bitwise Operator • This are used to manipulate the data at bit level • It operates only on integers

  41. The truth table for Bitwise AND,OR and XOR Bitwise Operator cont. Eg: x = 3 = 0000 0011 y = 4 = 0000 0100 x&y = 0000 0000 Eg: x = 3 = 0000 0011 y = 4 = 0000 0100 x|y = 0000 0111 Eg: x = 3 = 0000 0011 y = 4 = 0000 0100 x ^ y = 0000 0111

  42. Bitwise Operator cont. Bitwise One’s Complement The one’s complement operator (~) is a unary operator, which causes the bits of the operand to be inverted (i.e., one’s becomes zero’s and zero’s become one’s) For Example, if x = 7 i.e 8 – bit binary digit is 0 0 0 0 0 1 1 1 The One’s Complement is 1 1 1 1 1 0 0 0 Bitwise Left Shift Operator The Left shift operator (<<) shifts each bit of the operand to its Left. The general form or the syntax of Left shift operator is variable << no. of bits positions if x = 7 (i.e., 0 0 0 0 0 1 1 1) the value of y in the expression y = x <<1 is 14 0 0 0 0 1 1 1 0 = 14 since it shifts the bit position to its left by one bit. The value stored in x is multiplied by 2N (where n is the no of bit positions) to get the required value. For example, if x = 7 the result of the expression y = x << 2 is y = x * 22 (i.e. 28)

  43. Bitwise Operator cont. Bitwise Right Shift Operator The Right shift operator (>>) shifts each bit of the operand to its Right. The general form or the syntax of Right shift operator is variable >> no. of bits positions if x = 7 (i.e., 0 0 0 0 0 1 1 1) the value of y in the expression y = x >> 1 is 3 0 0 0 0 0 0 1 1 = 3 since it shifts the bit position to its right by one bit. The value stored in x is divided by 2N (where n is the no of bit positions) to get the required value. For example, if x = 7 the result of the expression y = x << 2 is y = x / 22 (i.e. 1). If you use the left shift operator i.e. x = x << 1 the value of x will be equal to 2 (i.e., 0 0 0 0 0 0 1 0) since the lost bit cannot be taken back.

  44. Special Operator Some of the special operators used in C language. These operators are referred as separators or punctuators. 1. Ampersand (&) 2. Comma (,) 3. Asterisk ( * ) 4. Ellipsis (…) 5. Braces ({}) 6. Hash (#) 7. Brackets ([]) 8. Parenthesis (()) 9. Colon (:) 10. Semicolon(;)

  45. Special Operator

  46. Special Operator

  47. Special Operator

  48. Operator Precedence and Associativity of Operator

  49. What is Precedence Rule and Associative Rule • Each operator in C has a precedence associated with it. • This precedence is used to determine how an expression involving more than one operator is evaluated. • These are distinct levels of precedence and an operator may belong to one of these levels. • The operators at the higher level of precedence are evaluated first. • The operators of the same precedence are evaluated either from ‘left to right’ or from ‘right to left’, depending on the level. • That is known as the associativity property of an operator.

  50. The precedence of an operator gives the order in which operators are applied in expressions: the highest precedence operator is applied first, followed by the next highest, and so on. eg: Arithmetic operator precedence Arithmetic operators precedence The arithmetic expression evaluation is carried out using two phases from left to right through the expressions

More Related