0% found this document useful (0 votes)
9 views39 pages

Unit 1 C

The document covers fundamental concepts in data representation, including various number systems (binary, octal, decimal, hexadecimal) and their characteristics. It also explains flowcharts and decision trees as tools for visualizing algorithms and decision-making processes, along with their advantages and disadvantages. Additionally, it introduces pseudocode, algorithms, and essential programming fundamentals such as character sets, keywords, identifiers, and data types in C programming.

Uploaded by

cheema1150
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)
9 views39 pages

Unit 1 C

The document covers fundamental concepts in data representation, including various number systems (binary, octal, decimal, hexadecimal) and their characteristics. It also explains flowcharts and decision trees as tools for visualizing algorithms and decision-making processes, along with their advantages and disadvantages. Additionally, it introduces pseudocode, algorithms, and essential programming fundamentals such as character sets, keywords, identifiers, and data types in C programming.

Uploaded by

cheema1150
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/ 39

Unit-I

Logic Development: Data Representation


 Data refers to the symbols that represent people, events, things, and
ideas. Data can be a name, a number, the colors in a photograph, or
the notes in a musical composition.
 Data Representation refers to the form in which data is stored,
processed, and transmitted.

Number systems are the technique to represent numbers in the


computer system architecture, every value that you are saving or
getting into/from computer memory has a defined number system.
Computer architecture supports following number systems.

 Binary number system


 Octal number system
 Decimal number system
 Hexadecimal (hex) number system

1) Binary Number System

A Binary number system has only two digits that are 0 and 1. Every
number (value) represents with 0 and 1 in this number system. The
base of binary number system is 2, because it has only two digits.

2) Octal number system

Octal number system has only eight (8) digits from 0 to 7. Every
number (value) represents with 0,1,2,3,4,5,6 and 7 in this number
system. The base of octal number system is 8, because it has only 8
digits.

3) Decimal number system


Decimal number system has only ten (10) digits from 0 to 9. Every
number (value) represents with 0,1,2,3,4,5,6, 7,8 and 9 in this number
system. The base of decimal number system is 10, because it has only
10 digits.

4) Hexadecimal number system

A Hexadecimal number system has sixteen (16) alphanumeric values


from 0 to 9 and A to F. Every number (value) represents with
0,1,2,3,4,5,6, 7,8,9,A,B,C,D,E and F in this number system. The base
of hexadecimal number system is 16, because it has 16 alphanumeric
values. Here A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.

Flowchart

A flowchart is a type of diagram that represents a workflow or


process. A flowchart can also be defined as a diagrammatic
representation of an algorithm, a step-by-step approach to solving
a task.

The flowchart shows the steps as boxes of various kinds, and their
order by connecting the boxes with arrows. This diagrammatic
representation illustrates a solution model to a given problem.
Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields.

The various symbols used in Flowchart Designs are given below.

o Terminal Symbol: In the flowchart, it is represented with the


help of a circle for denoting the start and stop symbol. The
symbol given below is used to represent the terminal symbol.

o Input/output Symbol: The input symbol is used to represent


the input data, and the output symbol is used to display the
output operation. The symbol given below is used for
representing the Input/output symbol.

o Processing Symbol:It is represented in a flowchart with the


help of a rectangle box used to represent the arithmetic and data
movement instructions. The symbol given below is used to
represent the processing symbol.

o Decision Symbol: Diamond symbol is used for represents


decision-making statements. The symbol given below is used to
represent the decision symbol.
o

o Connector Symbol:The connector symbol is used if flows


discontinued at some point and continued again at another place.
The following symbol is the representation of the connector
symbol.

o Flow lines: It represents the exact sequence in which


instructions are executed. Arrows are used to represent the flow
lines in a flowchart. The symbol given below is used for
representing the flow lines:

o Hexagon symbol (Flat): It is used to create a preparation box


containing the loop setting statement. The symbol given below
is used for representing the Hexagon symbol.
o

Advantages of Flowchart in C:

Following are the various advantages of flowchart:

o Communication: A flowchart is a better way of communicating


the logic of a program.
o Synthesis: Flowchart is used as working models in designing
new programs and software systems.
o Efficient Coding: Flowcharts act as a guide for a programmer
in writing the actual code in a high-level language.
o Proper Debugging: Flowcharts help in the debugging process.
o Effective Analysis: Effective analysis of logical programs can
be easily done with the help of a related flowchart.
o Proper Documentation: Flowchart provides better and proper
documentation. It consists of various activities such as
collecting, organizing, storing, and maintaining all related
program records.
o Testing: A flowchart helps in the testing process.
o Efficient program maintenance: The maintenance of the
program becomes easy with the help of a flowchart.

Disadvantages of Flowchart in C:

Following are the various disadvantages of flowchart:

o Time-consuming: Designing a flowchart is a very time-


consuming process.
o Complex: It isn't easy to draw a flowchart for large and
complex programs.
o There is no standard in the flowchart; there is no standard to
determine the quantity of detail.
o Difficult to modify: It is very difficult to modify the existing
flowchart.

Examples of flowchart:

Example 1:

Design a flowchart for adding two numbers entered by the user.

Example 2:
Design a flowchart for finding the largest among three numbers
entered by the user.
Problem Analysis
Identify the issues. Be clear about what the problem …
Understand everyone’s interests. …

List the possible solutions (options) …

Evaluate the options.

Select an option or options. …

Decision Tree
A decision tree is a graphical representation used to make decisions
and predict outcomes by mapping various possible choices and their
possible consequences.
A Decision Tree is a flowchart-like structure used to make decisions
based on a series of conditions. In C programming, this is often
represented by nested if-else or switch-case statements.

Components of a Decision Tree


The following major components are used in making a decision tree:-

 Root Node:
o The topmost node in a decision tree represents the entire
dataset or the initial question that needs to be answered.
 Decision Nodes:
o These internal nodes represent decision points or tests on
an attribute.
 Branches:
o This is the connectors between nodes that represent the
outcome of a decision or test.
o Example: “Yes” or “No” based outcomes.
 Leaf Nodes (Terminal Nodes):
o Endpoints of a decision tree that represent the outcome or
decision.

Working Mechanism

 Decision trees operate by recursively splitting the data into


subsets based on the value of input attributes.
 This process continues until all data is classified or a stopping
criterion is met.
 The tree structure allows easy interpretation of the decision-
making process

Example of a Decision Tree


A decision tree for deciding whether to play outside based on weather
conditions:
Root Node: Is it sunny?

o Decision Node: Yes
 Decision Node: Is it hot?
 Leaf Node: Yes -> Stay inside
 Leaf Node: No -> Play outside
o Decision Node: No
 Leaf Node: Stay inside

Use/Applications

 It is widely used in data mining, machine learning, and decision


analysis

Example: Grading System

Let's consider a simple problem: grading students based on their


scores.

Score Range Grade


90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
< 60 F

This can be modeled using a decision tree as follows:

 If score >= 90, grade is A.


 Else if score >= 80, grade is B.
 Else if score >= 70, grade is C.
 Else if score >= 60, grade is D.
 Else grade is F.
Decision Table
A Decision Table is a tabular method for representing and analyzing
decision rules and provides a systematic way to identify and
document various conditions and the corresponding actions to take
based on those conditions.

A Decision Table is a more compact way to represent decision-


making scenarios. It is essentially a matrix that lists all possible
conditions and their corresponding actions.

Characteristics

 They enhance clarity, ensure consistency, and facilitate effective


documentation and testing of decision rules.
 Decision tables are particularly useful in complex decision-
making processes where multiple conditions and actions need to
be considered simultaneously.

Components of a Decision Table


There are the following components used or focussed during the
creation of a Decision Table –

 Conditions:
o These are the different scenarios or criteria that need to be
evaluated.
 Actions:
o These are the possible outcomes or decisions that will be
executed based on the conditions.
 Condition Entries:
o These are the possible states or values for each condition.
 Action Entries:
o These are the specific actions to be taken for each set of
conditions.
Structure of a Decision Table
A typical decision table consists of four quadrants:-

 Conditions Stub: It lists/includes all the conditions.


 Actions Stub: It lists/includes all the possible actions.
 Conditions Entries: It specifies the values for each condition in
different scenarios.
 Actions Entries: It indicate the actions to be taken for each
combination of condition values.

Example of a Decision Table


A simplified example of a decision table for an online store’s order
processing system is:-
Conditions Rule 1 Rule 2 Rule 3 Rule 4

Customer Type New New Existing Existing

Order Amount > 500 No Yes No Yes

Actions

Offer Discount No Yes No Yes

Free Shipping No Yes No Yes

Priority Handling No Yes No Yes

In this table:

 Customer Type and Order Amount > 500 are the conditions.
 Offer Discounts, Free Shipping, and Priority Handling are
the actions.
 The rules specify different combinations of conditions and the
corresponding actions.

Pseudo code

Pseudocode is a simple way to write code that is not meant to be run


on a computer. It uses basic English words & phrases to describe what
a program should do. Pseudocode helps programmers plan out their
code before writing it in a specific programming language like C.
OR
A Pseudocode is defined as a step-by-step description of an
algorithm. Pseudocode does not use any programming language in
its representation instead it uses the simple English language text as
it is intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its
implementation(code) in a high-level language

What is the need for Pseudocode

Pseudocode is an important part of designing an algorithm, it helps


the programmer in planning the solution to the problem as well as
the reader in understanding the approach to the problem. Pseudocode
is an intermediate state between algorithm and program that plays
supports the transition of the algorithm into the program.

How to write Pseudocode?


Before writing the pseudocode of any algorithm the following points
must be kept in mind.
 Organize the sequence of tasks and write the pseudocode
accordingly.
 At first, establishes the main goal or the aim.

Example:

This program will print first N numbers of Fibonacci series.


START
DECLARE num1, num2, num3, average as float
INPUT num1, num2, num3
SET average = (num1 + num2 + num3) / 3
PRINT average
END
What is Algorithm | Introduction to Algorithms
The word Algorithm means ” A set of finite rules or instructions to
be followed in calculations or other problem-solving operations ”

Therefore Algorithm refers to a sequence of finite steps to solve a


particular problem.

What are the Characteristics of an Algorithm?


 Clear and Unambiguous: The algorithm should be unambiguous.
Each of its steps should be clear in all aspects and must lead to
only one meaning.
 Well-Defined Inputs: If an algorithm says to take inputs, it
should be well-defined inputs. It may or may not take input.
 Well-Defined Outputs: The algorithm must clearly define what
output will be yielded and it should be well-defined as well. It
should produce at least 1 output.
 Finite-ness: The algorithm must be finite, i.e. it should terminate
after a finite time.
 Feasible: The algorithm must be simple, generic, and practical,
such that it can be executed with the available resources. It must
not contain some future technology or anything.
 Language Independent: The Algorithm designed must be
language-independent, i.e. it must be just plain instructions that
can be implemented in any language, and yet the output will be
the same, as expected.
 Input: An algorithm has zero or more inputs. Each that contains a
fundamental operator must accept zero or more inputs.
 Output: An algorithm produces at least one output. Every
instruction that contains a fundamental operator must accept zero
or more inputs.
 Definiteness: All instructions in an algorithm must be
unambiguous, precise, and easy to interpret. By referring to any of
the instructions in an algorithm one can clearly understand what is
to be done. Every fundamental operator in instruction must be
defined without any ambiguity.
 Finiteness: An algorithm must terminate after a finite number of
steps in all test cases. Every instruction which contains a
fundamental operator must be terminated within a finite amount
of time. Infinite loops or recursive functions without base
conditions do not possess finiteness.
 Effectiveness: An algorithm must be developed by using very
basic, simple, and feasible operations so that one can trace it out
by using just paper and pencil.

Fundamentals:
 Character Set
 Keywords
 Identifiers
 Data types

`1. Character sets :

are used in forming either words or numbers or even expressions in C


programming. Characters in C are classified into 4 groups:

Letters

In C programming, we can use both uppercase and lowercase letters


of English language

 Uppercase Letters: A to Z
 Lowercase Letters: a to z
Digits

We can use decimal digits from 0 to 9.

Special Characters

C Programming allows programmer to use following special


characters:

comma , slash /

period . backslash

semicolon ; percentage %

colon : left and right brackets [ ]

question mark ? left and right parenthesis ( )

White Spaces

In C Programming, white spaces contains:

 Blank Spaces
 Tab
 Carriage Return
 New Line
2. Keywords

Keywords are special words in C programming which have their own


predefined meaning. The functions and meanings of these words
cannot be altered. Some keywords in C Programming are:

32 Keyword

auto break case char

continue const do default

double else enum extern

for float go if

int long register return

sign static sizeof short

struct switch typedef union

void volatile while unsigned

Consider an example below:

int age;

float height;
Here, int is a keyword which declares age as a variable of integer
data type.

Similarly, float is also a keyword which declares height is a variable


of floating integer data type.

3. Identifiers

Identifiers are user-defined names of variables, functions and arrays.


It comprises of combination of letters and digits. In C Programming,
while declaring identifiers, certain rules have to be followed viz.

 It must begin with an alphabet or an underscore and not digits.


 It must contain only alphabets, digits or underscore.
 A keyword cannot be used as an identifier
 Must not contain white space.
 Only first 31 characters are significant.
Let us again consider an example
int age1;
float height_in_feet;
Here, age1 is an identifier of integer data type.
Similarly height_feet is also an identifier but of floating integer data
type

Data types

Each variable in C has an associated data type. It specifies the type


of data that the variable can store like integer, character, floating,
double, etc.
Each data type requires different amounts of memory
The data type is a collection of data with values having fixed values,
meaning as well as its characteristics.
The data types in C can be classified as follows:
Types Description

Primitive data types are the most basic data types


Primitive
that are used for representing simple values such
Data Types
as integers, float, characters, etc.

User Defined The user-defined data types are defined by the


Data Types user himself.

The data types that are derived from the primitive


Derived
or built-in datatypes are referred to as Derived
Types
Data Types.

Below is a list of ranges along with the memory requirement and


format specifiers on the 32-bit GCC compiler
Data Type Size (bytes) Range Format Specifier

short int 2 -32,768 to 32,767 %hd

unsigned short int 2 0 to 65,535 %hu

unsigned int 4 0 to 4,294,967,295 %u

int 4 -2,147,483,648 to 2,147,483,647 %d

long int 4 -2,147,483,648 to 2,147,483,647 %ld

unsigned long int 4 0 to 4,294,967,295 %lu

long long int 8 -(2^63) to (2^63)-1 %lld

unsigned long long int 8 0 to 18,446,744,073,709,551,615 %llu

signed char 1 -128 to 127 %c

unsigned char 1 0 to 255 %c

float 4 %f
1.2E-38 to 3.4E+38

double 8 %lf
1.7E-308 to 1.7E+308

long double 16 %Lf


3.4E-4932 to 1.1E+4932
// C program to print Integer data types.

#include <stdio.h>

int main()

int a = 9;

int b = -9;

int c = 89U;

long int d = 99998L;

printf("Integer value with positive data: %d\n", a);

printf("Integer value with negative data: %d\n", b);

printf("Integer value with an unsigned int data: %u\n",c);

printf("Integer value with an long int data: %ld", d);

return 0;

// C program to print Character data types.

#include <stdio.h>

int main()

{
char a = 'a';

char c;

printf("Value of a: %c\n", a);

return 0;

Constants
The constants refer to fixed values that the program may not alter
during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like

 an integer constant,  a floating constant,


 a charater constant, or
 a string literal. The Constants are treated just like regular
variables except that their values cannot be modified after their
definition.

Valid decimal integer constants: 8 , 943 ,12767

Invalid Decimal integer constants :

82 ,65 ( , ) is not allowed

36.0 ( .) is not allowed

5 0 410 Blankspace not allowed

20 - 100 ( -) is not allowed

0987 The first digit should not be a zero


Variables
A variable is nothing but a name given to a storage area that our
programs can manipulate.
Each variable in C has a specific type, which determines the size and
layout of the variable’s memory;
the range of values that can be stored within that memory;
and the set of operations that can be applied to the variable.

All variables have three essential attributes :

the name

the value

the memory, where the value is stored

User defined variable must follow the following rules:

 First character must be a letter or underscore, remaining characters


can be letters or digits or underscore.

 Lowercase and upper case letters are different

 Although there is no restriction on the variable names, but only


first 8 character are taken, so the first 8 character of two variable
should be different.

 Variable should not be reserved word i.e. keyword.

 Each variable must be declared before its usage within the


program, this declaration is achieved by linking variable name to its
type.
Declaring Variables

int a;

float b;

Initializing Variables: The values are assigned just after the


declarations are made

int i=10;

Expressions:
An expression is a formula in which operands are linked to each other
by the use of operators to compute a value. An operand can be a
function reference, a variable, an array element or a constant.
Eg. 6*2/8 + 8 * 2

Statements:

 Three kinds of statements in C:


o Expression Statements
o Compound Statements
o Control Statements

1.Expression Statements

 An expression followed by a semi-colon


 Execution of the statement causes the expression to be evaluated

Examples

i = 0;

i++;

a = 5 + i;
y = (m * x) + b;

printf("Slope = %f", m);

2.Compound Statement
A sequence of statements within a pair of curly braces { } forms a
single compound statement or block.

{
float speed;

printf("Speed = %f ", speed);


}

3.Control Statements

 Used for loops, branches, and logical tests

Eg.

If( )

}
What is a C Operator?
An operator in C can be defined as the symbol that helps us to
perform some specific mathematical, relational, bitwise,
conditional, or logical computations on values and variables

The values and variables used with operators are called


operands.

c = a + b;
Here, ‘+’ is the operator known as the addition operator, and ‘a’ and
‘b’ are operands

Types of Operators in C

C language provides a wide range of operators that are:


1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5.Conditional Operators

1. Arithmetic Operations in C

The arithmetic operators are used to perform


arithmetic/mathematical operations on operands. There are 9
arithmetic operators in C language:
S. No. Symbol Operator Description Syntax

Adds two
+ Plus a+b
1 numeric values.

Subtracts right
– Minus operand from a–b
2 left operand.

Multiply two
* Multiply a*b
3 numeric values.

Divide two
/ Divide a/b
4 numeric values.

Returns the
remainder after
% Modulus diving the left a%b
operand with the
5 right operand.

// C program to illustrate the arithmatic operators

#include <stdio.h>

int main()

int a = 25, b = 5;

printf("a + b = %d\n", a + b);

printf("a - b = %d\n", a - b);

printf("a * b = %d\n", a * b);

printf("a / b = %d\n", a / b);


printf("a % b = %d\n", a % b);

return 0;

Output
a + b = 30
a - b = 20
a * b = 125
a/b=5
a%b=0

2. Relational Operators in C
The relational operators in C are used for the comparison of the two
operands. All these operators are binary operators that return true or
false values as the result of comparison.
These are a total of 6 relational operators in C:
S. No. Symbol Operator Description Syntax

Returns true if the left


operand is less than the
< Less than a<b
right operand. Else
1 false

Returns true if the left


operand is greater than
> Greater than a>b
the right operand. Else
2 false

Returns true if the left


operand is less than or
<= Less than or equal to a <= b
equal to the right
3 operand. Else false

Returns true if the left


Greater than or operand is greater than
>= a >= b
equal to or equal to right
4 operand. Else false
S. No. Symbol Operator Description Syntax

Returns true if both the


== Equal to a == b
5 operands are equal.

Returns true if both the


!= Not equal to operands are NOT a != b
6 equal.

// C program to illustrate the relational operators

#include <stdio.h>

int main()

int a = 25, b = 5;

// using operators and printing results

printf("a < b : %d\n", a < b);

printf("a > b : %d\n", a > b);

printf("a <= b: %d\n", a <= b);

printf("a >= b: %d\n", a >= b);

printf("a == b: %d\n", a == b);

printf("a != b : %d\n", a != b);

return 0;

Output
a<b :0
a>b :1
a <= b: 0
a >= b: 1
a == b: 0
a != b : 1

4. Logical Operator in C

Logical Operators are used to combine two or more


conditions/constraints or to complement the evaluation of the
original condition in consideration. The result of the operation of a
logical operator is a Boolean value either true or false.
S. No. Symbol Operator Description Syntax

Returns true
Logical if both the
&& a && b
AND operands are
1 true.

Returns true
if both or any
|| Logical OR of the a || b
operand is
2 true.

Returns true
Logical
! if the operand !a
NOT
3 is false.
// C program to illustrate the logical operators

#include <stdio.h>

int main()

int a = 25, b = 5;

// using operators and printing results

printf("a && b : %d\n", a && b);

printf("a || b : %d\n", a || b);

printf("!a: %d\n", !a);

return 0;

Output
a && b : 1
a || b : 1
!a: 0

5. Assignment Operators in C

Assignment operators are used to assign value to a variable. The left


side operand of the assignment operator is a variable and the right
side operand of the assignment operator is a value.
S. No. Symbol Operator Description Syntax

Assign the value of the


= Simple Assignment right operand to the a=b
1 left operand.

Add the right operand


and left operand and
+= Plus and assign a += b
assign this value to the
2 left operand.

Subtract the right


operand and left
-= Minus and assign operand and assign this a -= b
value to the left
3 operand.

Multiply the right


operand and left
*= Multiply and assign operand and assign this a *= b
value to the left
4 operand.

Divide the left operand


with the right operand
/= Divide and assign a /= b
and assign this value to
5 the left operand.

Assign the remainder


in the division of left
%= Modulus and assign operand with the right a %= b
operand to the left
operand.
6

// C program to illustrate the assignment operators

#include <stdio.h>

int main()

int a = 25, b = 5;
// using operators and printing results

printf("a = b: %d\n", a = b);

printf("a += b: %d\n", a += b);

printf("a -= b: %d\n", a -= b);

printf("a *= b: %d\n", a *= b);

printf("a /= b: %d\n", a /= b);

printf("a %%= b: %d\n", a %= b);

return 0;

Output
a = b: 5
a += b: 10
a -= b: 5
a *= b: 25
a /= b: 5
a %= b: 0

6.Conditional Operator ( ? : )
 The conditional operator is the only ternary operator in C++.
 Here, Expression1 is the condition to be evaluated. If the
condition(Expression1) is True then we will execute and return
the result of Expression2 otherwise if the condition(Expression1)
is false then we will execute and return the result of Expression3.
 Syntax
 operand1 ? operand2 : operand3;
// C program to find largest among two

#include <stdio.h>

int main()

int m = 5, n = 4;

(m > n) ? printf("m is greater than n that is %d > %d",

m, n)

: printf("n is greater than m that is %d > %d",

n, m);
return 0;

Output
m is greater than n that is 5 > 4

7.Unary operators in C
Unary operators are the operators that perform operations on a
single operand to produce a new value.

Types of unary operators are mentioned below:


1. Unary minus ( – )
2. Increment ( ++ )
3. Decrement ( — )
4. NOT ( ! )
5. Addressof operator ( & )
6. sizeof()

. Unary Minus
The minus operator ( – ) changes the sign of its argument. A
positive number becomes negative, and a negative number becomes
positive.
int a = 10;
int b = -a; // b = -10
#include <stdio.h>
int main()
{
int a = 100;
int b = -a;
printf("a = %d\n", a);
printf("b = %d",b);
return 0;
}
Output
a = 100
b = -100

2. Increment
The increment operator ( ++ ) is used to increment the value of the
variable by 1. The increment can be done in two ways:
2.1 prefix increment
In this method, the operator precedes the operand (e.g., ++a). The
value of the operand will be altered before it is used.
Example:
int a = 1;
int b = ++a;
2.2 postfix increment
In this method, the operator follows the operand (e.g., a++). The
value operand will be altered after it is used.
Example:
int a = 1;
int b = a++;
int c = a;
// C program to illustrate increment
#include <stdio.h>

int main()
{
int a = 5;
int b = 5;
printf("Pre-Incrementing a = %d\n", ++a);
printf("Post-Incrementing b = %d", b++);
return 0;
}
Output:

Pre-Incrementing a =6

Post-Incrementing b =5

3.Decrement
The decrement operator ( — ) is used to decrement the value of the
variable by 1. The decrement can be done in two ways:
3.1 prefix decrement
In this method, the operator precedes the operand (e.g., – -a). The
value of the operand will be altered before it is used.
Example:
int a = 1;
int b = --a;
3.2 postfix decrement
In this method, the operator follows the operand (e.g., a- -). The
value of the operand will be altered after it is used.
Example:
int a = 1;
int b = a--;
int c = a;
// C program to illustrate decrement

#include <stdio.h>

int main()
{
int a = 5;
int b = 5;
printf("Pre-Decrementing a = %d\n", --a);
printf("Post-Decrementing b = %d", b--);
return 0;
}
Output:

Pre-Decrementing a =4

Post-Decrementing b =5

4. sizeof() operator

This operator returns the size of its operand, in bytes.


The sizeof() operator always precedes its operand. The operand is
an expression, or it may be a cast.
Note: The `sizeof()` operator in C++ is machine dependent. For
example, the size of an ‘int’ in C++ may be 4 bytes in a 32-bit
machine but it may be 8 bytes in a 64-bit machine.
Below is the implementation of sizeof() operator:

// C program to illustrate the sizeof operator

#include <stdio.h>

int main()

{ printf("Size of double: %d\n", sizeof(double));

printf("Size of int: %d\n", sizeof(int));

return 0;

}
Output
Size of double: 8
Size of int: 4

You might also like