C Programming PDF - Tata Elxsi
Document Details
Uploaded by YoungValley2027
Tata Elxsi
2020
null
null
Tags
Summary
These notes cover C programming concepts such as expressions, operators (unary, binary, ternary), types of operators (arithmetic, relational, logical, bitwise, compound assignment, conditional), and expression statements. The presentation also includes examples, and the author's details.
Full Transcript
CC –Programming Programming Learning and Development Tuesday, November 3, 2020 1 Expressions Day -1 and operators 2 Expressions An expression consists of at least one operand and zero or more operators. Operands are objects...
CC –Programming Programming Learning and Development Tuesday, November 3, 2020 1 Expressions Day -1 and operators 2 Expressions An expression consists of at least one operand and zero or more operators. Operands are objects such as constants, variables, and function calls that return values. 47 2+2 cosine(3.14159) Parentheses group subexpressions: ( 2 * ( ( 3 + 10 ) - ( 2 * 6 ) ) ) 3 Operators There are three categories of operators in C. - Unary operators - Binary Operators - Ternary Operators 4 Types of operators Unary : [ + - ! ~ ++ - - (type)* & sizeof ] Arithmetic Operators : [ * , / , + , - ] Relational Operators: [ ,==,!=,= ] Logical Operators [ &&,||,! ] Bitwise Operators [ >,^,&,|, ] Ternary or Conditional Operators: [ ?: ] Assignment Operator : [ = += -= *= /= %=>>= y Less than < Is operand 1 less than operand 2? x= Is operand 1 greater than or equal to operand 2? x>=y to Less than or equal to Is operand 1 greater than operand 2? x>y Less than < Is operand 1 less than operand 2? x= Is operand 1 greater than or equal to operand 2? x>=y to Less than or equal to 1 = %d\n", x >> 3); //3 = 31 / 9 return 0; } 26 Precedence and Order of Evaluation Operators Associativity () [] ->. left to right ! ~ ++ -- +(u) -(u) *(u) sizeof() right to left */% left to right +- left to right > left to right < >= left to right == != left to right &,^,| left to right && , || left to right ?: right to left = += -= *= /= %= &= ^= |= = right to left 27 Type cast Type cast is to explicitly cause an expression to be of a specified data type. A type cast consists of a type specifier enclosed in parentheses, followed by an expression. To ensure proper casting, you should also enclose the expression that follows the type specifier in parentheses. - float x; - int y = 7; - int z = 3; - x = (float) (y / z); 28 statement We write statements to cause actions and to control flow within programs. You can also write statements that do not do anything at all, or do things that are uselessly trivial. iTotal = 100 + 200; While(1){ ; } 29 Expression Statements Expressions can be turned into a statement by adding a semicolon to the end of the expression. - 5; - 2 + 2; - 10 >= 9; Expression statements are only useful when they have some kind of side effect, such as storing a value, calling a function, or (this is esoteric) causing a fault in the program. - x++; - y = x + 25; - puts ("Hello, world"); - *iPtr; 30 Thank you Thank You Learning & Development, Tata Elxsi, Bangalore. ITPB Road Whitefield Bangalore 560 048 India [email protected] www.tataelxsi.com Confidentiality Notice This document and all information contained herein is the sole property of Tata Elxsi Limited and shall not be reproduced or disclosed to a third party without the express written consent of Tata Elxsi Limited. 31