100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Computer system £10.49
Add to cart

Lecture notes

Computer system

 0 view  0 purchase

Computer system, computer science, computer skills, computer language

Preview 3 out of 21  pages

  • July 24, 2023
  • 21
  • 2017/2018
  • Lecture notes
  • Prof
  • All classes
All documents for this subject (5)
avatar-seller
akhilagouri
Multiple increment operators inside printf
#include<stdio.h>
void main() {
int i = 1;
printf("%d %d %d", i, ++i, i++);
}
Output : 3 3 1



Pictorial representation




Explanation of program

I am sure you will get confused after viewing the above image and output of program.
1. Whenever more than one format specifiers (i.e %d) are directly or indirectly related with
same variable (i,i++,++i) then we need to evaluate each individual expression from right
to left.
2. As shown in the above image evaluation sequence of expressions written inside printf
will be – i++,++i,i
3. After execution we need to replace the output of expression at appropriate place
No Step Explanation

Evaluate
1 At the time of execution we will be using older value of i = 1
i++

Evaluate At the time of execution we will be increment value already modified after
2
++i step 1 i.e i = 3

2 Evaluate i At the time of execution we will be using value of i modified in step 2




C PROGRAMMING Page 40

,Postfix and Prefix Expression in Same Statement
#include<stdio.h>
#include<conio.h>
void main() {
int i = 0, j = 0;
j = i++ + ++i;
printf("%d\n", i);
printf("%d\n", j);
}

Output :
2
2

Explanation of Program




Conditional Operator/ Ternary operator:
conditional operator checks the condition and executes the statement depending of the condition.
A conditional operator is a ternary operator, that is, it works on 3 operands.
Conditional operator consist of two symbols.

1 : question mark (?).
2 : colon ( : ).


C PROGRAMMING Page 41

, Syntax : condition ? exp1 : exp2;

It first evaluate the condition, if it is true (non-zero) then the “exp1” is
evaluated, if the condition is false (zero) then the “exp2” is evaluated.

#include <stdio.h>
int main(){
char February;
int days;
printf("If this year is leap year, enter 1. If not enter any integer: ");
scanf("%c",&February);
// If test condition (February == 'l') is true, days equal to 29.
// If test condition (February =='l') is false, days equal to 28.
days = (February == '1') ? 29 : 28;
printf("Number of days in February = %d",days);
return 0;
}

Output
If this year is leap year, enter 1. If not enter any integer: 1
Number of days in February = 29


Bitwise Operators:
Bitwise operators are used to manipulate the data at bit level. It operates on integers only. It
may not be applied to float.In arithmetic-logic unit (which is within the CPU), mathematical
operations like: addition, subtraction, multiplication and division are done in bit-level which
makes processing faster and saves power. To perform bit-level operations in C programming,
bitwise operators are used.

Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Shift left
>> Shift right
~ One‟s complement.


Bitwise AND operator &
The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an
operand is 0, the result of corresponding bit is evaluated to 0.
Let us suppose the bitwise AND operation of two integers 12 and 25.
12 = 00001100 (In Binary)
25 = 00011001 (In Binary)
C PROGRAMMING Page 42

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller akhilagouri. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £10.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

50843 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 14 years now

Start selling
£10.49
  • (0)
Add to cart
Added