This document discusses operators and expressions in C. It defines operands and operators, and describes the different types of operators in C including arithmetic, relational, logical, assignment, increment/decrement, conditional, bitwise, and comma operators. It explains the properties of operators such as precedence and associativity. Examples are provided to demonstrate how each operator works. The document also discusses the rules for evaluating expressions and provides additional examples.
A storage class defines the scope (visibility) and life time of variables and/or functions within a C++ Program. There are following storage classes which can be used in a C++ Program
auto
register
static
extern
A storage class defines the scope (visibility) and life time of variables and/or functions within a C++ Program. There are following storage classes which can be used in a C++ Program
auto
register
static
extern
In C and all other Programming languages, loops allow a set
of instructions to be performed until a certain condition is reached. This condition may be predefined as in the for loop, or open-ended as in the while and do loops.
Decision-making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be
executed if the condition is determined to be true, and
optionally, other statements to be executed if the condition is determined to be false.
Shown below is the general form of a typical decision-making structure found in most of the programming languages:
If any class have multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class.
If you have to perform one single operation but with different number or types of arguments, then you can simply overload the function.
In C and all other Programming languages, loops allow a set
of instructions to be performed until a certain condition is reached. This condition may be predefined as in the for loop, or open-ended as in the while and do loops.
Decision-making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be
executed if the condition is determined to be true, and
optionally, other statements to be executed if the condition is determined to be false.
Shown below is the general form of a typical decision-making structure found in most of the programming languages:
If any class have multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class.
If you have to perform one single operation but with different number or types of arguments, then you can simply overload the function.
18 css101j pps unit 2
Relational and logical Operators - Condition Operators, Operator Precedence - Expressions with pre / post increment operator - Expression with conditional and assignment operators - If statement in expression - L value and R value in expression -
Control Statements – if and else - else if and nested if, switch case - Iterations, Conditional and Unconditional branching
For loop - while loop - do while, goto, break, continue
Array Basic and Types - Array Initialization and Declaration - Initialization: one Dimensional Array - Accessing, Indexing one Dimensional Array Operations - One Dimensional Array operations - Array Programs – 1D
This slide contains information about Operators in C.pptxranaashutosh531pvt
This slide contains information about c++ operators,This slide contains information about This slide contains information about c++ operators,This slide contains information about c++ operators,This slide contains information about c++ operators,This slide contains information about c++ operators,
C++ provides operators for composing arithmetic, relational, logical, bitwise, and conditional expressions. It also provides operators which produce useful side-effects, such as assignment, increment, and decrement. We will look at each category of operators in turn. We will also discuss the precedence rules which govern the order of operator evaluation in a multi-operator expression.
C Preprocessor directives:
i\ Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.
Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.
Pointers in C language is a variable that stores/points the address of another variable. A Pointer in C is used to allocate memory dynamically i.e. at run time.
C for Loop
Loops are used in programming to execute a block of code repeatedly until a specified condition is met. In this tutorial, you will learn to create for loop in C programming.
C programming has three types of loops:
for loop
while loop
do...while loop
Generations of Computer
Introduction:
A computer is an electronic device that manipulates information or data. It has the ability to store, retrieve, and process data.
Nowadays, a computer can be used to type documents, send email, play games, and browse the Web. It can also be used to edit or create spreadsheets, presentations, and even videos. But the evolution of this complex system started around 1946 with the first Generation of Computer and evolving ever since.
There are five generations of computers.
Storage Classes in C
Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program.
C - Unions
A union is a special data type available in C that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose.
Structures in C
What is a structure?
A structure is a user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
Functions - C Programming
What is a Function? A function is combined of a block of code that can be called or used anywhere in the program by calling the name. ...
Function arguments. Functions are able to accept input parameters in the form of variables. ...
Function return values
Dynamic memory allocation in c languageTanmay Modi
C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely malloc, realloc, calloc and free. ... Their performance varies in both execution time and required memory.
Decision making in C. Decision making is about deciding the order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met. C language handles decision-making by supporting the following statements, if statement.
Array in C Language
Featured snippet from the web
C - Arrays
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. ... A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
2. 2+3
Operand
Operator
Operand: a data item on which operators
perform operations.
Operator: a symbol that tells the compiler to
perform specific mathematical or logical
functions.
Definition:
3. Operators in C
C language is rich in built-in operators and provides the
following types of operators −
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operator
7. Bitwise operators
8. Comma operator
4. Properties of Operators
i)Precedence:
priority given to the operator for a process
In arithmetic operators,*,/,% are highest
priority and similar precedence,+ and –
have lowest precendence.
Example: 8+9*2-10
=8+18-10
=26-10
=16
5. ii) Associativity:
Direction of execution.
Used when an expression has operators
with equal precedence.
Two types:
A)left to right:
◦ Example: 12*4/8%2
◦ Since all operators have same
precedence,proceed left to right.
=48/8%2
=6%2
=0
6. A) Right to Left:
◦ Example: x=8+5%2
◦ Assignment operator has right to left
associativity,hence right side solved
first(8+1=9) and then assigned to left
side.(x=9)
8. Rules for evaluation of
expression
1. First parenthesized sub expression from left to
right are evaluated.
2. If parentheses are nested, the evaluation begins
with the innermost sub expression
3. The precedence rule is applied in determining the
order of application of operators in evaluating sub
expressions
4. The associatively rule is applied when 2 or more
operators of the same precedence level appear
in a sub expression.
5. Arithmetic expressions are evaluated from left to
right using the rules of precedence
6. When parentheses are used, the expressions
within parentheses assume highest priority
11. Comma Operator(,)
Used to separate two or more
expressions.
Lowest priority
Not essential to parenthesise.
void main()
{
printf(“addition =%d n Subtraction=%d,2+3,5-4);
}
Addition=5
Subtraction=1 //first +evaluated,then , evaluated
12. Conditional Operator(? :)
Contains condition followed by two
statement or values.
Ternary operator:takes 3 arguments.
If condition true,first statement
executed,otherwise second executed.
Syntax:
Condition? (expression1): (expression2)
void main()
{
printf(“result =%d”,2==3?4:5);
}
Result=5
14. Arithmetic Operators
Operator example Meaning
+ a + b Addition
- a – b Subtraction
* a * b Multiplication
/ a / b Division
% a % b Modulo division- remainder
Cannot be
used with
reals
15. Binary Operators
%,* and %
◦ are solved first.
◦ have equal level of precedence.
◦ When occur together,solved from left to
right.
+ and –
◦ solved after /,*,%.
◦ have equal level of precedence.
◦ evaluated from left to right.
16. Unary Operators
Operator Example Meaning
- -a Minus
++ a ++ Increment
-- a -- Decrement
& &a Address operator
sizeof sizeof(a) Gives the size of an
operator
17. A)minus(-):
• used for indicating or changing the
algebraic sign of a value.
• Example:
int x=-50 assigns the value of -50 to x.
• No unary plus(+) in C,even though a
value assigned with + sign is valid,still not
used in practice.
18. B)Increment and Decrement
Operators:
Used because fast as compared to
assignment counterpart.
++ adds a value 1 to the operand
-- subtracts 1 from its operand.
Prefix ++a or a++ Postfix
--a or a--
19. Rules for ++ & -- operators
1. These require variables as their
operands
2. When postfix either ++ or -- is used
with the variable in a given expression,
the expression is evaluated first and
then it is incremented or decremented
by one
3. When prefix either ++ or – is used with
the variable in a given expression, it is
incremented or decremented by one
first and then the expression is
evaluated with the new value
20. Examples for ++ & --
operators
Let the value of a =5 and b=++a then
a = b =6
Let the value of a = 5 and b=a++ then
a =5 but b=6
i.e.:
1. a prefix operator first adds 1 to the
operand and then the result is
assigned to the variable on the left
2. a postfix operator first assigns the
value to the variable on left and then
increments the operand.
24. C)sizeof and ‘&’Operator:
Sizeof gives the bytes occupied by a
variable.
Size of a variable depends upon its
datatype.
‘&’ prints address of the variable in
memory.
25. void main()
{
int x=2;
float y=2;
clrscr();
printf(“n sizeof(x)= %d bytes”,sizeof(x));
printf(“n sizeof(y)= %d bytes”,sizeof(y));
printf(“n address of x= %u and y=%u”,x,y));
}
Sizeof(x)=2
Sizeof(y)=4
Address of x=4088 and y=34567
26. Relational Operators
Used to distinguish between two
values depending on their relation.
Provide the relationship between two
expressions.
If the relation is true,then it returns a
value 1otherwise 0 for false.
binary operators because they take
two expressions as operands.
27. Relational Operators
Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Equal to
!= Not equal to
29. Assignment Operator(=)
Used for assigning a value.
Syntax:
v op = exp;
where v = variable,
op = shorthand assignment
operator
exp = expression
Ex: x=x+3
x+=3
31. Logical Operators
The logical relationship between the
two expressions is tested with logical
operators.
Can be used to join two expressions.
After checking the conditions,it
provides logical true(1) or false(0)
status.
32. Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Rules:
&& provides true result when both
expressions are true,otherwise 0.
|| provides true result when one of the
expressions is true,otherwise 0.
! Provides 0 if the condition is
true,otherwise 1.
33. Truth Table
a b
Value of the expression
a && b a || b
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
35. Practice questions
Q1.Write a program to display 1 if inputted
number is between 1 and 100 otherwise
0.Use the logical and(&&)operator.
void main()
{
printf(“enter number:”);
scanf(“%d”,&x);
z=(x>=1 && x<=100 ? 1 : 0);
printf(“z=%d”,z);
}
36. Practice questions
Q2.Write a program to display 1 if inputted
number is either 1 or 100 otherwise
0.Use the logical or(||)operator.
void main()
{
printf(“enter number:”);
scanf(“%d”,&x);
z=(x==1 || x==100 ? 1 : 0);
printf(“z=%d”,z);
}
37. Practice questions
Q3.Write a program to display 1 if the
inputted number is except 100 otherwise
0.Use the logical not(!)operator.
void main()
{
printf(“enter number:”);
scanf(“%d”,&x);
z=(x!=100 ? 1 : 0);
printf(“z=%d”,z);
}
38. Bitwise Operators
These operators allow manipulation of
data at the bit level.
These operators can operate only on
integer operands such as
int,char,short,long.
39. Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
~ One’s complement
41. Example
Assume A = 60 and B = 13.
In binary format, they will be as follows −
A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
42. Right Shift
It is denoted by >>
Bit Pattern of the data can be shifted by
specified number of Positions to Right
When Data is Shifted Right , leading zero’s
are filled with zero.
Right shift Operator is Binary Operator [Bi –
two]
43. Right shift
Q.Write a program to shift inputted data by two
bits rights.
void main()
{
int x,y;
printf(“read the integer from the keyboard:”);
scanf(“%d”,&x);
x>>=2;
y=x;
printf(“the right shifted data is : %d”,y);
}
44. Left Shift
It is denoted by <<
Bit Pattern of the data can be shifted by
specified number of Positions to Left
When Data is Shifted Left , trailing zero’s
are filled with zero.
Left shift Operator is Binary Operator [Bi –
two]
45. Left shift
Q.Write a program to shift inputted data by two
bits left.
void main()
{
int x,y;
printf(“read the integer from the keyboard:”);
scanf(“%d”,&x);
x<<=2;
y=x;
printf(“the right shifted data is : %d”,y);
}