Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
Operators and Expressions Rohit Khokher. Operators and Expression OperatorsSymbols Arithmetic+ - * / % Relational >= == != Logical&& || ! Assignment=
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
Introduction to C Language
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
Computer Programming Control Structure
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
GUJARAT KNOWLEDGE VILLAGE Faculty Name:- Prof H.M.Patel Students Name:- SONI VISHAL THAKKER BHAVIN ZALA JAYDIP ZALA.
INTRODUCTION TO C. C was developed by Dennis Ritchie at Bell laboratory in 1972 It is an upgrade version of languages B and BCPL.
Operators & Expressions
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
UNIT II C PROGRAMMING BASICS Problem formulation – Problem Solving - Introduction to ‘ C’ programming –fundamentals – structure of a ‘C’ program – compilation.
CS 161 Introduction to Programming and Problem Solving Chapter 12 C++ Statements Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
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.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
Operators & Expressions
Arithmetic Expressions
Chapter Topics The Basics of a C++ Program Data Types
Operators And Expressions
INTRODUCTION TO C.
Decisions Chapter 4.
Basic Elements of C++.
Introduction to C++.
Computer Programming: C language
Introduction to C Programming
Basic Elements of C++ Chapter 2.
Visit for more Learning Resources
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C Programming
Chapter-3 Operators.
Conversion Check your class notes and given examples at class.
Lecture3.
UNIT - 3 Noornilo Nafees.
Introduction to Programming – 4 Operators
Chapter 3 Operators and Expressions
Chapter 4: Expression and Operator
C – Programming Language
Session 1 – Introduction to Computer and Algorithm (Part 2)‏
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
C Programming Mr. KAJAL MAJI ASSISTANT PROFESSOR DEPARTMENT OF PHYSICS
INTRODUCTION TO C.
Presentation transcript:

Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator Conditional operator

Arithmetic operator It is used to carry out arithmetic operations like addition, subtraction etc, Eg: +, -, *, / etc,

Sample program #include // Header File #include int b=10; //Global Declaration void main ( ) /* main is the starting of every c program */ { int a,c; //Local Declaration clrscr( ); scanf(“%d”,&a); printf(“ \n The sum of the two values:”); c = a+b; printf(“%d”,c); getch( ); }

Division operator on Different Data Type OperationResultExample int/intint5/2 = 2 int/realreal5/2.0 = 2.5 real/intreal5.0/2 = 2.5 real/realreal5.0/2.0 = 2.5

Sample program #include void main ( ) { int a=10,b=4,c; float d=3,e; clrscr( ); c = a/b; printf(" \n value a/b is:%d",c); e = a/d; printf("\n value a/d is:%f",e); getch( ); }

Output value a/b is:2 value a/d is:

Relational operator It is used to compare two or more operands. Eg :, =, != etc,. 5 < 9 which will return 1

Logical operator It is used to combine the result of two or more condition. AND(&&) OR (||) NOT (!) are Logical operators. Eg: (i>10)&&(j>5). (i>10)||(j>5) etc,.

Sample program #include void main ( ) { int a=10,b=3,c=5,e; clrscr( ); if(a>b) // relational operator { printf(" \n a is bigger than b"); } if((a>b)&&(a>c)) //Logical operator { printf(" \n a is biggest"); } getch( ); }

Output a is bigger than b a is biggest

Assignment operator It is used to assign a value or expression etc to a variable. Eg: a =10. a = b a = b + c etc,.

Assignment operator(Cont) Compound operator It is also used to assign a value to a variable. Eg: x + = y means x = x + y Nested operator It is used for multiple assignment. Eg: i = j = k = 0;

Sample program #include int b=10; void main ( ) { int a=3,b=5; clrscr( ); a+=b; // a= a+b printf(" \n The sum of the two values:%d",a); getch( ); }

Output The sum of the two values:8

Increment or decrement operator(Unary) It is used to Increment or decrement an operand. Eg: ++x (Pre Increment), x++ (Post Increment), --x (Pre Decrement), x-- (Post Decrement).

Sample Program #include void main ( ) { int a=5; clrscr( ); printf(" \n Post increment Value:%d",a++); printf(" \n Pre increment Value:%d",++a); printf(" \n Pre decrement Value:%d",--a); printf(" \n Post decrement Value:%d",a--); getch( ); }

Output Post increment Value:5 Pre increment Value:7 Pre decrement Value:6 Post decrement Value:6

Bitwise operator It is used to manipulate data at bit level. Eg: a=5 i.e b=4 i.e Then a & b = a | b = etc,.

Sample program #include void main ( ) { int a=5,b=4,c; //char a=5,b=4,c; clrscr( ); c = a&b; printf(" \n value a&b is:%d",c); getch( ); }

Output value a&b is:4

Conditional Operator (or) Ternary Operator It is used to checks the condition and execute the statement depending on the condition. Eg: C = a > b ? a:b

Sample Program #include void main ( ) { int a=5,b=8,c; clrscr( ); c = a>b?a:b; //Conditional operator printf(" \n The Larger Value is%d",c); getch( ); }

Output The Larger Value is 8

Special Operator comma operator (, ) sizeof operator pointer operator (&, *) etc,.

#include void main ( ) { int c; clrscr( ); printf(" \n size of int is:%d",sizeof c); getch( ); }

Output size of int is: 2

Expression An expression represent data item such as variable, constant are interconnected using operators. Eg: ExpressionC Expression a + b + c a 2 +b 2 a*a + b*b

Operator Precedence & Associativity The arithmetic expressions evaluation are carried out based on the precedence and associativity. The evaluation are carried in two phases. – First Phase: High Priority operators are evaluated. – Second Phase: Low Priority operators are evaluated.

PrecedenceOperator High*, /, % Low+, -

Example /4 + 3*3 – 1 = – 1 = – 1 = 9 – 1 = 8

Example 5 – (20/4) + 3*(3 – 1) = *2 = = 6

Type Conversion Converting the type of an expression from one type to another type. Eg: x = (int)10.45

Sample Program #include void main ( ) { int c; clrscr( ); c=(int)10.45; printf("\nOutput is:%d",c); getch( ); } OUTPUT Output is:10

Input/Output Function Input/Output Function Unformatted Formatted Output printf() fprintf() Input scanf() fscanf() Input getc() gets() getchar() Output putc() puts() putchar()

Formatted Input/Output C uses two functions for formatted input and output. Formatted input : reads formatted data from the keyboard. Formatted output : writes formatted data to the monitor.

Formatted Input and Output

Standard Output The standard output file is the monitor. Like the keyboard, it is a text file. When you need to display data that is not text, it must be converted into to the text before it is written to the screen.

Format of printf Statement

Formatted Input (scanf) The standard formatted input function in C is scanf (scan formatted). scanf consists of : a format string. an address list that identifies where data are to be placed in memory. scanf ( format string, address list ); ( “ %c ….%d …..%f ….. ”, &a, ….&i, …..,&x …..)

Format of scanf Statement

Character Test Function It is used to test the character taken from the input. isalpha(ch) isdigit(ch) islower(ch) isupper(ch) tolower(ch) toupper(ch) etc,.