
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of various operators in c programming, including comparison, logical, compound, and assignment operators. It also covers control structures such as if statements, switch statements, and loops (for, while, do-while). Additionally, it explains input and output operations using printf and scanf functions.
Typology: Slides
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























^ == test equality
x == y
assignment
x = y
not equal ^ >=
greater than or equal ^ <=
less than or equal
greater than ^ <
less than ^ no space between operators ^ = = is invalid
^ Syntax:
if (expression) statement; ^ If the expression is true (not zero), thestatement is executed. ^ If the expression is false, it is notexecuted. ^ You can group multiple expressionstogether with braces:
if (expression) {statement 1;statement 2;statement 3;}
^ Equal to
if (x==10)
^ Not equal to
if (x!=10)
^ Less than
if (x<10)
^ Greater than
if (x>10)
^ Less than / equal to
if (x<=10)
^ Greater than / equal to
if (x>=10)
if(income
printf(“pay
tax”);
else
printf(“find
a^
better
job”);
one
of
these
statements
always
execute
Single statements:^ if^
( condition)true_statement; else false_statement
;
Multiple statements:^ if^
( condition)
{
……} else^ { …… }
^ Switch statements look like thisexample:
switch
(expression)
{
value_
:^ statements_1;
break;
value_
:^ statements_2;
break;
...value_n
:^ statements_n;
break
default
^ The increment Operator^
Increment
x++ or ++x
^ Decrement
x–- or –-x
^ Shorthand Assigns^
x*=
(multiply x by 3; x = x * 3) ^ x+=
(add 5 to x) ^ x-=10 (subtract 10 from 6) ^ x/=
(halve x)
^ set rules for precedence ^ use parenthesis
marks
printf(“passed”)
printf(“failed”); condition^ ^ marks >50 Execute^ ^ 1st statement if condition is true^ ^ 2nd statement if condition is false
printf
(“the
answer
is
= %d”,
x);
^ Specifies data type & where to get thevalue to display.
printf
(“%8.4f %d\n”, total,
sum);
^ display^
a real #
total with 4 decimal places
^ an integer
sum
scanf(“%f”,&num_f);
^ read in floating point value
^ Repeat a series of statements ^ Not reasonable to copy statementsmultiple time ^ Need a way to repeat a block of code ^ Loops allow repetition