0% found this document useful (0 votes)
30 views7 pages

Unit 3 & 4 Input Output & Operators

The document discusses formatted and unformatted input/output functions in C. Formatted functions like printf() and scanf() allow formatting output and input using specifiers, while unformatted functions like getch() and putchar() only work with characters. The document also covers C operators, their types, and precedence.

Uploaded by

Sakar Sapkota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views7 pages

Unit 3 & 4 Input Output & Operators

The document discusses formatted and unformatted input/output functions in C. Formatted functions like printf() and scanf() allow formatting output and input using specifiers, while unformatted functions like getch() and putchar() only work with characters. The document also covers C operators, their types, and precedence.

Uploaded by

Sakar Sapkota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

FORMATTED & UNFORMATTED INPUT AND OUPUT

FUNCTION
Formatted I/O functions are used to take various inputs from the user and display
multiple outputs to the user. These types of I/O functions can help to display the output
to the user in different formats using the format specifiers.

Why they are called formatted I/O?

These functions are called formatted I/O functions because we can use format specifiers
in these functions and hence, we can format these functions according to our needs.

printf() and scanf() in C


The printf() and scanf() functions are used for input and output in C language. Both
functions are inbuilt library functions, defined in stdio.h header file.

printf() function
The printf() function is used for output. It prints the given statement to the console.

The syntax of printf() function is given below:

printf("format specifier" ,varaiable _list);

The format specifier can be %d (integer), %c (character), %s (string), %f (float) etc.

scanf() function
The scanf() function is used for input. It reads the input data from the console.

Syntax for scanf() function is given below

scanf("format specifier" ,&variable_list);


Unformatted I/O Functions
Unformatted I/O functions are used only for character data type or character
array/string and cannot be used for any other datatype. These functions are used to
read single input from the user at the console and it allows to display the value at the
console.

Why they are called unformatted I/O?

These functions are called unformatted I/O functions because we cannot use format
specifiers in these functions and hence, cannot format these functions according to our
needs.

The following unformatted I/O functions will be discussed in this section-

getch()
getche()
getchar()
putchar()
gets()
puts()
putch()

Expression Statement in C
An expression statement consists of an expression followed by a semicolon. The
execution of such a statement causes the associated expression to be evaluated.

The symbol used to calculate the expression is called operator and except operator
everything is operand.

Example:

a = 6;
c = a + b;
++j;
C Operators
An operator is simply a symbol that is used to perform operations. There can be many
types of operations like arithmetic, logical, bitwise, etc.

There are following types of operators to perform different types of operations in C


language.

Arithmetic Operator
Relational Operator
Logical Operators
Bitwise Operators
Assignment Operator
Ternary or Conditional Operators
Increment/Decrement Operator

Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction,
multiplication, division etc on numerical values (constants and variables).

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulo Division

Relational Operators
A relational operator checks the relationship between two operands. If the relation is
true, it returns 1; if the relation is false, it returns value 0.

Relational operators are used in decision making and loops.


> Greater than

< Less than

>= Greater than equal to

<= Less than equal to

== Double equal to

!= Not equal to

Logical Operator
An expression containing logical operator returns either 0 or 1 depending upon whether
expression results true or false. Logical operators are commonly used in decision making
in C programming.

&& (logical AND)


|| (logical OR)
! (logical NOT)

Bitwise Operators
Bitwise operators are used in C programming to perform bit-level operations.

During computation, mathematical operations like: addition, subtraction, multiplication,


division, etc are converted to bit-level which makes processing faster and saves power.

& (Bitwise AND)


| (Bitwise OR)
^ (Bitwise X-OR)
~ (Bitwise complement)
>> (Bitwise Right Shift)
<< (Bitwise Left Shift)

Assignment Operator
An assignment operator is used for assigning a value to a variable. The most common
assignment operator is =.
=
+=
-=
*=
/=
%=

Conditional/Ternary Operator
The operators, which require three operands to act upon, are known as ternary
operators. It can be represented by “? :”. It is also known as conditional operator. The
operator improves the performance and reduces the line of code.

Syntax

Expression1? Expression2: Expression3

Exmple

a<b ? a : b

Increment and Decrement Operators


C programming has two operators increment ++ and decrement -- to change the value
of an operand (constant or variable) by 1.

Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1.


These two operators are unary operators, meaning they only operate on a single
operand.

Precedence of Operators in C
The precedence of operator species that which operator will be evaluated first and next.
The associativity specifies the operator direction to be evaluated; it may be left to right
or right to left.

Let's understand the precedence by the example given below

int a=10+20*10;
The a variable will contain 210 because * (multiplicative operator) is evaluated before +
(additive operator).

The precedence and associativity of C operators is given below:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy