 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Operator. Assignation (=). The assignation operator serves to assign a value to a variable. a = 5; It is necessary to emphasize that the assignation operation.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Introduction to C Programming
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Introduction to C Language
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
4. Python - Basic Operators
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
C Operators. CONTENTS CONDITIONAL OPERATOR SIMPLE ASSIGNMENT OPERATOR COMPOUND ASSIGNMENT OPERATOR BITWISE OPERATOR OPERATOR PRECEDENCE.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Control Structures (B) Topics to cover here: Sequencing in C++ language.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
CS 161 Introduction to Programming and Problem Solving Chapter 12 C++ Statements Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Lecture2.
Operators & Expressions
CSE 220 – C Programming Expressions.
University of Central Florida COP 3330 Object Oriented Programming
INSPIRING CREATIVE AND INNOVATIVE MINDS
Chapter 2 - Introduction to C Programming
University of Central Florida COP 3330 Object Oriented Programming
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 2 - Introduction to C Programming
Introduction to C Programming
C Operators, Operands, Expressions & Statements
Chapter-3 Operators.
Chapter 2 - Introduction to C Programming
Lecture3.
Introduction to Programming – 4 Operators
Chapter 3 Operators and Expressions
Chapter 2 - Introduction to C Programming
OPERATORS in C Programming
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
OPERATORS in C Programming
Presentation transcript:

 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators Conditional Operators Bitwise Operators  Precedence and Associativity Of OperatorsPrecedence and Associativity Of Operators Precedence of operators Associativity of operators

The formatted Input / Output functions can read and write values of all data types, provided the appropriate conversion symbol is used to identify the data type. scanf is used for receiving formatted Input printf is used for displaying formatted output. Syntax for scanf: scanf(“control_string 1, - -, control_string n”,&variable1, ,variable n); Syntax for printf: printf(“control_string 1, - -, control_string n”,variable1, , variable n); Back

Example - 1 #include //This is needed to run printf() function. int main() { printf("C Programming"); //displays the content inside quotation return 0; } Explanation of how this program works:  Every program starts from main() function.  printf() is a library function to display output which only works if #include is included at the beginning.

 Here, stdio.h is a header file (standard input output header file) and #include is command to paste the code from the header file when necessary. When compiler encounters printf() function and doesn't find stdio.h header file, compiler shows error.  Code return 0; indicates the end of program. You can ignore this statement but, it is good programming practice to use return 0; Example - 2 #include int main() { int c=5; printf("Number=%d",c); return 0; } Output: Number=5

Example - 3 #include int main() { int c; printf("Enter a number:\n"); \scanf("%d",&c); printf("Number=%d",c); return 0; } Enter a number: 4 Number=4 Back

Operators are the symbol which operates on value or a variable. Operators in C programming  Arithmetic Operators  Assignment Operators  Relational Operators  Logical Operators  Conditional Operators  Bitwise Operators  Arithmetic Operators: Operator Meaning of Operator + addition or unary plus - subtraction or unary minus * multiplication / division % remainder after division Back

/* Program to demonstrate the working of arithmetic operators in C. */ #include int main() { int a=9,b=4,c; c=a+b; printf("a+b=%d\n",c); c=a-b; printf("a-b=%d\n",c); c=a*b; printf("a*b=%d\n",c); c=a/b; printf("a/b=%d\n",c); c=a%b;

printf("Remainder when a divided by b=%d\n",c); return 0; } Output: a+b=13 a-b=5 a*b=36 a/b=2 Remainder when a divided by b=1 Back

 Assignment Operators: The assignment operator is =. This operator assigns the value in right side to the left side. var=5 //5 is assigned to var a=c; //value of c is assigned to a 5=c; // Error! 5 is a constant. Back

 Relational Operator: Relational operators checks relationship between two operands. If the relation is true, it returns value 1 and if the relation is false, it returns value 0. For example: a>b Here, > is a relational operator. If a is greater than b, a>b returns 1 if not then, it returns 0. Operator Meaning of Operator Example == Equal to 5==3 returns false (0) > Greater than 5>3 returns true (1) < Less than 5<3 returns false (0) != Not equal to 5!=3 returns true(1) >= Greater than or equal to 5>=3 returns true (1) <= Less than or equal to 5<=3 return false (0) Back

 Logical Operators: Logical operators are used to combine expressions containing relation operators. Operator Meaning of Example Operator && Logical AND If c=5 and d=2 then,((c==5) && (d>5)) returns false || Logical OR If c=5 and d=2 then, ((c==5) || (d>5)) return true ! Logical NOT If c=5 then, !(c==5) returns false

Explanation : For expression, ((c==5) && (d>5)) to be true, both c==5 and d>5 should be true but, (d>5) is false in the given example. So, the expression is false. For expression ((c==5) || (d>5)) to be true, either the expression should be true. Since, (c==5) is true. So, the expression is true. Since, expression (c==5) is true, !(c==5) is false. Back

 Conditional Operator: Conditional operator takes three operands and consists of two symbols ? and :. Conditional operators are used for decision making in C. For example: c=(c>0)?10:-10; If c is greater than 0, value of c will be 10 but, if c is less than 0, value of c will be -10. Back

 Bitwise Operators: A bitwise operator works on each bit of data. Bitwise operators are used in bit level programming. Operators Meaning of operators & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR ~ Bitwise complement << Shift left >> Shift right Bitwise operator is advance topic in programming. Back

 Precedence of operators: If more than one operators are involved in an expression then, C language has predefined rule of priority of operators. This rule of priority of operators is called Operator Precedence. In C, precedence of arithmetic operators(*,%,/,+,-) is higher than relational operators(==,!=,>, =,<=) and precedence of relational operator is higher than logical operators(&&, || and !). (a>b+c&&d) This expression is equivalent to: ((a>(b+c))&&d) i.e, (b+c) executes first then, (a>(b+c)) executes then, (a>(b+c))&&d) executes Back

 Associativity of operators : Associativity indicates in which order two operators of same precedence(priority) executes. Let us suppose an expression: a==b!=c Here, operators == and != have same precedence. The associativity of both == and != is left to right, i.e, the expression in left is executed first and execution take pale towards right. Thus, a==b!=c equivalent to : (a==b)!=c. Back

Thank You