0% found this document useful (0 votes)
12 views

CP Unit 1

Uploaded by

User Interface
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)
12 views

CP Unit 1

Uploaded by

User Interface
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/ 108

Prof. Sohel A.

Khan
Assistant Professor

Department of Artificial Intelligence and Data Science


Programme Syllabus

Syllabus Semester I
Course Computer Programming
Course Type ESC Course Code AI24103
Credits 04 L-4, T-0, P – 0
Course Outcomes: On successful completion of the
course the learner will be able to:
CO Course Outcomes BT PO
Level
1 To learn the fundamentals of C Programming 1 1,2
2 To implement Control Statements in C Programming 3 1,2,4
3 To use derived data types as Arrays for problem solving 3 1,2
techniques
4 To utilize functions for Program Optimization 3 1,2,3
5 To apply the concept of pointers to perform various 3 1,3
operations.
6 To develop user defined types using structures and to 5 1,2,4
implement various file handling functions.
Unit No. Content
Introduction to C Programming:
Evolution of C programming, Fundamentals
of Algorithm, Fundamentals of C
Programming: Identifiers, Data Types,
Variables & Constants, Keywords; Program
1
structure: Preprocessor Directives, Basic
input and Output Functions, Format
Expressions, Operators, precedence &
Associativity, Simple C program and its
execution.
Chapter I
Oldest

Fastest
Famous

Important
Evolution of C programming
History of C:
The C programming language has a rich history,
dating back to the early 1970s:
• Early Development (1969-1973):
C was created by Dennis Ritchie at Bell Labs.
• Standardization (1978):
Brian Kernighan and Dennis Ritchie published the
book "The C Programming Language," often
referred to as K&R C. This book acted as the de
facto standard for C for many years.

Brian Kernighan
• C99 (1999):
The next major revision, C99, introduced new features
like variable-length arrays, inline functions, and improved
support for floating-point arithmetic.
• C11 (2011):
This version added features like type-generic expressions,
anonymous structures, and improved multi-threading
support.
• C17 (2018):
Primarily a bug-fix and clarification update to C11, with
no major new features.
Algorithm
• An algorithm is a step-by-step procedure for
solving a problem in a finite amount of time.

An algorithm is thus a sequence of computational steps that


transform the input into the output.
Notations and Steps to write algorithm
Characteristics
• Finiteness
• Definiteness
• Input
• Output
• Effectiveness
• Generality
• Accuracy
• Sequence
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)

• Statements:
• Statement is a single action in a computer.
Input a=5,b=2
Process a+b
Result c=a+b
Output print
State:
Transition from one process to another process under
specified condition with in a time is called state.
• Control flow:
The process of executing the individual
statements in a given order is called control
flow.
The control can be executed in three ways
1. sequence
2. selection
3. iteration
Sequence
• All the instructions are executed one after
another is called sequence execution.

Example:
Add two numbers:
Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
Selection:
• A selection statement causes the program control to
be transferred to a specific part of the program
based upon the condition.
Example
Write an algorithm to check whether he
is eligible to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
Iteration:
• In some programs, certain set of statements are
executed again and again based upon conditional
test. i.e. executed more than one time. This type of
execution is called looping or iteration.
Example
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: go to step 4
Step 7: Stop
Flow Chart
Flow chart is defined as graphical representation of the logic
for problem solving.
The purpose of flowchart is making the logic of the program
clear in a visual representation.

Notation
Rules for drawing a flowchart

1. The flowchart should be clear, neat and easy to follow.


2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process
symbol.

4. Only one flow line should enter a decision symbol.


However, two or three flow lines may leave the decision
symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
Token
• Smallest individual unit of a program is known
as token.
• Token is the building block of c program.
• It is classified into 6 types
• Identifier
• Keywords
• Variable
• Constant
• Character set
• String
Character Set
“Character set in C programming
language denotes any alphabet, digit, or special
symbol used to represent information.”

Characters are the smallest unit of a string and


take up the memory space of 1 byte each.
Types Of Character Sets In C
Character set
Letters: Both uppercase (A-Z) and lowercase (a-z)
alphabets.
Digits: The numerals from 0 to 9.
Special Characters: These include symbols like +, -, *, /, =,
<, >, &, |, !, ^, ~, %, #, \, ;, :, ', " and more.
Whitespace Characters: These include spaces, tabs,
newlines, and form feeds.
Escape Sequences: These are special meaning characters
prefixed with a backslash, such as \n (newline), \t (tab), \\
(backslash character), \' (single quote), and \" (double
quote).
Identifier
What is Identifier
Identifiers refer to the names you give to
entities .
Such as variable, function, keywords, etc.
e.g Students_name, circle, area, ptr etc.
Constant
• A constant is an entity that doesn’t change.
• E.g 426, ‘’A”, etc.
Types of C Constants
C constants can be divided into two major
categories:
(a) Primary Constants
(b) Secondary Constants
(a) Primary Constants
• Primary Constant include three different constant namely integer
constant, Real constant and Character Constant.
• Rules for Constructing Integer Constants
(a) An integer constant must have at least one digit.
(b) It must not have a decimal point.
(c) It can be either positive or negative.
(d) If no sign precedes an integer constant it is assumed to be
positive.
(e) No commas or blanks are allowed within an integer constant.
(f) The allowable range for integer constants is -32768 to 32767.
• E.g Integer Constatnt 23, 567, -32456 etc.
• Real Constant also floating point constant
• The real constants could be written in two forms —
Fractional form and Exponential form.
Rules for constructing real constants in fractional Form
a) A real constant must have at least one digit.
b) It must have a decimal point.
c) It could be either positive or negative.
d) Default sign is positive.
e) No commas or blanks are allowed within a real constant.
• Ex.: +325.34
426.0
-32.76
-48.5792
• Rules for constructing real constant in exponential form
a) The mantissa part and the exponential part should be separated
by a letter e.
b) The mantissa part may have a positive or negative sign.
c) Default sign of mantissa part is positive.
d) The exponent must have at least one digit, which must be a
e) positive or negative integer. Default sign is positive.
f) Range of real constants expressed in exponential form is -3.4e38
to 3.4e38.
Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5
• Rules for Constructing Character Constants
• A character constant is a single alphabet, a single digit or a
single special symbol enclosed within single inverted
commas. Both the inverted commas should point to the
left. For example, ’A’ is a valid character constant whereas
‘A’ is not.
• The maximum length of a character constant can be 1
character.
Ex.: 'A'
'I'
'5'
'='
C Variables
• an entity that may vary during program
execution is called a variable.
• For example x is variable with reference the
address of memory which store
data/information.
• E.g x=5 may change to x=3

x 5 x 3
• Rules for Constructing Variable Names
• A variable name is any combination of 1 to 31 alphabets, digits or
underscores. Some compilers allow variable names whose length
could be up to 247 characters. Still, it would be safer to stick to the
rule of 31 characters. Do not create unnecessarily long variable
names as it adds to your typing effort.
• The first character in the variable name must be an alphabet or
underscore.
• No commas or blanks are allowed within a variable name.
• No special symbol other than an underscore (as in gross_sal)
• can be used in a variable name.
• Ex.: si_int
m_hra
pop_e_89
How to declare Variable
• Syntax
Data type name_of_variable;
Assignment
name_of_variable = value;
C keywords
• Keywords are reserve words which can not
use as a variable .
• It is also called reserve word.
• Keywords are the words whose meaning has
already been explained to the C compiler (or
in a broad sense to the computer).
• There are only 32 keywords available in C.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do If static while
1) Documentation section

It includes the statement specified at the beginning of a program, such as a


program's name, date, description, and title. It is represented as:

/*
Overview of the code

*/

2) Preprocessor section

The preprocessor section contains all the header files used in a program. It
informs the system to link the header files to the system libraries. It is given by:

#include<stdio.h>
#include<conio.h>
3) Define section

The define section comprises of different constants declared using the define
keyword. It is given by:

#define a = 2

4) Global declaration

The global section comprises of all the global declarations in the program. It is
given by:
float num = 2.54;
int a = 5;
char ch ='z';
5) Main function( )

• main() is the first function to be executed by the computer. It is necessary for a


code to include the main(). It is like any other function available in the C
library. Parenthesis () is used for passing parameters (if any) to a function.

• We can also use int or void with the main ().


Function Name Description Example

Void/int main() The void main() specifies that the


program will not return any value.
The int main() specifies that the
program can return integer-type
data.
main function The main function is further
categorized into local declarations,
statements, and expressions.
6) Local declarations

The variable that is declared inside a given function or block is referred to as


local declarations.
6) User-defined functions

The user-defined functions specified the functions specified as per the


requirements of the user. For example, color(), sum(), division(), etc.

The program (basic or advanced) follows the same sections as listed above.
// C Program to illustrate how to use #define to
declare constants
#include <stdio.h>
// Defining macros with a constant value OUTPUT:
#define PI 3.14159265359 Area of Circle of radius
int main() 21: 1385
{ int radius = 21;
int area;
// Using macros to calculate the area of a circle
area = PI * radius * radius;
printf("Area of Circle of radius %d: %d", radius,
area);
return 0;
}
My First C Program
Comments are
ignored by
compiler

/* This Program Print Hello World on Screen */


Preprocessor directives

#include<stdio.h>
Each C program Must have
Void main(){ one main Function

print(“Hello World”); Print Hello World on screen


}
Each C
statements end
with semicolon ;
Data Type
• It specifies the type of data that the variable
can store.
• Each variable in C has an associated data type
• Each data type requires different amounts of
memory and has some specific operations
which can be performed over it.
The following are some main primitive data
types in C:
Integer Data Type
• The integer datatype in C is used to store the integer
numbers(any number including positive, negative and zero
without decimal part). Octal values, hexadecimal values,
and decimal values can be stored in int data type in C.
• Range: -2,147,483,648 to 2,147,483,647
• Size: 4 bytes
• Format Specifier: %d
• Syntax for variable declaration
• int var_name;
• E.g int number;
The integer data type can also be used as
• unsigned int: Unsigned int data type in C is used
to store the data values from zero to positive
numbers but it can’t store negative values like
signed int.
• short int: It is lesser in size than the int by 2 bytes
so can only store values from -32,768 to 32,767.
• long int: Larger version of the int datatype so can
store values greater than int.
• unsigned short int: Similar in relationship with
short int as unsigned int with int.
// C program to print Integer data types.
#include <stdio.h>

int main()
{
// Integer value with positive data.
int a = 9;

// integer value with negative data.


int b = -9;

// U or u is Used for Unsigned int in C.


int c = 89U;

// L or l is used for long int in C.


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;
}
• Character Data Type
• Character data type allows its variable to store only a single
character. The size of the character is 1 byte. It is the most
basic data type in C. It stores a single character and requires
a single byte of memory in almost all compilers.
• Range: (-128 to 127) or (0 to 255)
• Size: 1 byte
• Format Specifier: %c
• Syntax of char
char var_name;
e.g char grade;
#include <stdio.h>
int main() {
char ch = 'A';
printf("The character is: %c\n",ch);
return 0;
}
• Float Data Type
• In C programming float data type is used to store
floating-point values. Float in C is used to store decimal
and exponential values. It is used to store decimal
numbers (numbers with floating point values) with
single precision.
• Range: 1.2E-38 to 3.4E+38
• Size: 4 bytes
• Format Specifier: %f
• Syntax of float
float var_name;
• #include <stdio.h>
int main() {
float number = 3.14159;
printf("The floating-point number is: %f\n",
number);
return 0;
}
• Double Data Type
• A Double data type in C is used to store decimal
numbers (numbers with floating point values) with
double precision. It is used to define numeric values
which hold numbers with decimal values in C.
• The double data type is basically a precision sort of
data type that is capable of holding 64 bits of decimal
numbers or floating points.
• Range: 1.7E-308 to 1.7E+308
• Size: 8 bytes
• Format Specifier: %lf
Void Data Type
• The void data type in C is used to specify that
no value is present. It does not provide a
result value to its caller. It has no values and
no operations. It is used to represent nothing.
Void is used in multiple ways as function
return type, function arguments as void,
and pointers to void.
• void name_function()
// C program to demonstrate
// use of void pointers
#include <stdio.h>
void main(){

}
Preprocessor Directives
• Before we talk about directives first should
understand about preprocessor.
• “Preprocessors are programs that process the
source code before compilation.”
Let take a look steps involved between writing and
execution of code
Preprocessor Directives in C
• Preprocessor programs provide preprocessor directives
that tell the compiler to preprocess the source code before
compiling.
• All of these preprocessor directives begin with a ‘#’ (hash)
symbol.
• The ‘#’ symbol indicates that whatever statement starts
with a ‘#’ will go to the preprocessor program to get
executed.
• We can place these preprocessor directives anywhere in
our program.
• Examples of some preprocessor directives
are: #include, #define, #ifndef, etc.
Basic Input and Output in C
• C language has standard libraries that allow input
and output in a program.
• The stdio.h or standard input output library in C
that has methods for input and output.
scanf()
• The scanf() method, in C, reads the value from
the console as per the type specified and store it
in the given address.
• Syntax:
• scanf("%X", &name_of_variable);
• where %X is the format specifier in C.
• It is a way to tell the compiler what type of
data is in a variable and & is the address
operator in C, which tells the compiler to
change the real value of name_of_variable,
stored at this address in the memory.

• printf()
• The printf() method, in C, prints the value passed
as the parameter to it, on the console screen.
• Syntax:
printf("%X", name_of_variable);
• where %X is the format specifier in C.
• It is a way to tell the compiler what type of data is
in a variable and name_of_variable is the
variable to be printed.
How to take input and output of basic types in C?

The Syntax for input and output for these are:


• Integer:
Input: scanf("%d", &intVariable);
Output: printf("%d", intVariable);
• Float:
Input: scanf("%f", &floatVariable);
Output: printf("%f", floatVariable);
• Character:
Input: scanf("%c", &charVariable);
Output: printf("%c", charVariable);
1. // C program to show input and output
2. #include <stdio.h>
3. int main()
4. {
5. // Declare the variables
6. int num;
7. char ch;
8. float f;
9. // --- Integer ---
10. // Input the integer
11. printf("Enter the integer: ");
12. scanf("%d", &num);
13. // Output the integer
14. printf("\nEntered integer is: %d", num);
15. // --- Float ---
16. //For input Clearing buffer
17.
18. // Input the float
19. printf("\n\nEnter the float: ");
20. scanf("%f", &f);
21. // Output the float
22. printf("\nEntered float is: %f", f);
23. // --- Character ---
24. // Input the Character
25. printf("\n\nEnter the Character: ");
26. scanf("%c", &ch);
27. // Output the Character
28. printf("\nEntered character is: %c", ch);
29. return 0;
30. }
• Output
Enter the integer: 10
Entered integer is: 10
Enter the float: 2.5
Entered float is: 2.500000
Enter the Character: A
Entered Character is: A
In every C program, three basic task take place – accepting of data as input, the
processing of data, and the generation of output.
Types of Input and Output Functions:
1) Unformatted IO functions:
Unformatted input and output functions read a single input sent by the user and
permits to display the value as the output at the console.

a) character IO functions: getchar() and putchar()

b) string IO functions: gets() and puts()

2) Formatted IO functions:

We use the formatted input and output functions in the C language for taking single

or multiple inputs from the programmer/user at the console.

Ex/ Char, Int, Float, String=> scanf() and printf()


1) Unformatted Input & Output Functions:

a) Character Input & Output Functions:

• getchar()

C getchar is a standard library function that


takes a single input character from standard input.

Syntax Variable name=getchar();

Example Char Ch;


Ch=getchar();
• putchar():
The putchar() function in C displays a single character on the
screen

Syntax putchar(variablename);

Example Char Ch;


Ch=getchar();
putchar(Ch);
Note:
getchar() and putchar() can only handle a
single character at a time.
Example 1: The following program reads a single
key into a char variable −
#include <stdio.h> Enter a character: W
#include<conio.h>
int main() W
{ char ch;
clrscr();
printf("Enter a character: ");
ch = getchar();
putchar(ch);
return 0;
}
Example :

Implement a C Program to print 2-character


using getchar and putchar input output
functions.
#include <stdio.h> Enter a character: Hi
#include<conio.h>
int main() Hi
{ char ch1,ch2;
clrscr();
printf("Enter a 2 character: ");
ch1 = getchar();
ch2 = getchar();
putchar(ch1);
putchar(ch2);
return 0;
}
b) String Input & Output Functions:

a) gets()
• The gets() allows the user to enter the space-
separated strings.
• It returns the string entered by the user.
Syntax gets(variablename);

Example char name[20];


gets(name);
puts()
• puts() is a function used to display strings on
screen.

Syntax puts(variablename);

Example char name[30];


gets(name);
puts(name);
Example 1: The following example shows how you
can use the gets() and puts function −
#include <stdio.h> Enter your name:
Denis Ritchie
int main()
{ char name[20]; You entered the
printf("Enter your name: "); name is: Denis
gets(name); //reads string from user Ritchie
printf("You entered the name is: ");
puts(name); //displays string
return 0;
}
What is an Expression

• Expression: An expression is a combination of


operators, constants and variables. An expression
may consist of one or more operands, and zero or
more operators to produce a value.
• Constant expressions: Constant Expressions consists of only constant
values. A constant value is one that doesn’t change.
• Examples:
5, 10 + 5 / 6.0, 'x’
• Integral expressions: Integral Expressions are those which produce
integer results after implementing all the automatic and explicit type
conversions.
• Examples:
x, x * y, x + int ( 5.0)
where x and y are integer variables.
• Floating expressions: Float Expressions are which produce floating point
results after implementing all the automatic and explicit type
conversions.
Examples:
x + y, 10.75
where x and y are floating point variables.
• Relational expressions: Relational Expressions give
results of type boolean which takes a value true or
false.
Relational expressions are also known as Boolean
expressions.
Examples: x <= y, x + y > 2
• Logical expressions: Logical Expressions combine two
or more relational expressions and produces Boolean
type results.
Examples: x > y && x == 10, x == 10 || y == 5
• Pointer expressions: Pointer Expressions produce
address values.
Examples:&x, ptr, ptr++ where x is a variable and ptr is
a pointer.
• Bitwise expressions: Bitwise Expressions are
used to manipulate data at bit level. They are
basically used for testing or shifting bits.
Examples:
x << 3shifts three bit position to left
y >> 1shifts one bit position to right.
Shift operators are often used for multiplication
and division by powers of two.
Operators in C
• 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.
• we can say that the operators are the symbols
that perform operations on operands.
Types of Operators in C

• C language provides a wide range of operators


that can be classified into 6 types based on their
functionality:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Other 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 numeric
1 + Plus
values.
a+b

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

Multiply two
3 * Multiply
numeric values.
a*b

Divide two numeric


4 / Divide
values.
a/b

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

right operand.

Used to specify the


6 + Unary Plus
positive values.
+a

Flips the sign of the


7 – Unary Minus
value.
-a

Increases the value


8 ++ Increment
of the operand by 1.
a++

Decreases the value


9 — Decrement
of the operand by 1.
a–
2. Relational Operators in C
• The relational operators in C are used for the
comparison of the two operands.
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
1 < Less than
the right operand.
a<b
Else false

Returns true if the left


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

Returns true if the left


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

Returns true if the left


Greater than or equal operand is greater
4 >=
to than or equal to right
a >= b
operand. Else false

Returns true if both


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

Returns true if both


6 != Not equal to the operands are NOT a != b
equal.
3. 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.
S. No. Symbol Operator Description Syntax

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

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

Returns true if
3 ! Logical NOT the operand is !a
false.
4. Bitwise Operators in C
• The Bitwise operators are used to perform bit-
level operations on the operands.
• The operators are first converted to bit-level
and then the calculation is performed on the
operands.
• Mathematical operations such as addition,
subtraction, multiplication, etc. can be
performed at the bit level for faster
processing.
S. No. Symbol Operator Description Syntax
Performs bit-by-bit AND
1 & Bitwise AND operation and returns the a&b
result.

Performs bit-by-bit OR
2 | Bitwise OR operation and returns the a|b
result.

Performs bit-by-bit XOR


3 ^ Bitwise XOR operation and returns the a^b
result.

Bitwise First Flips all the set and unset


4 ~
Complement bits on the number.
~a

Shifts the number in


binary form by one place
5 << Bitwise Leftshift
in the operation and
a << b
returns the result.

Shifts the number in


binary form by one place
6 >> Bitwise Rightshilft
in the operation and
a >> b
returns the result.
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.
• The value on the right side must be of the
same data type as the variable on the left side
otherwise the compiler will raise an error.
6. Other Operators
• sizeof Operator
• Comma Operator ( , )
• Conditional Operator ( ? : )
Conditional Operator ( ? : )
Precedence & Associativity
• Precedence of operators
• The precedence of operators determines which operator is
executed first if there is more than one operator in an
expression.

• Let us consider an example:


int x = 5 - 17* 6;
• In C,
the precedence of * is higher than - and =.
Hence, 17 * 6 is evaluated first.
Then the expression involving - is evaluated as the
precedence of - is higher than that of =.
Associativity of Operators
• The associativity of operators determines the
direction in which an expression is evaluated.
For example,
b = a;
• Here, the value of a is assigned to b, and not
the other way around. It's because the
associativity of the = operator is from right to
left.
• if two operators of the same precedence
(priority) are present, associativity determines
the direction in which they execute.
• Let us consider an example:
1 == 2 != 3
Here, operators == and != have the same
precedence. And, their associativity is from left to
right. Hence, 1 == 2 is executed first.
• The expression above is equivalent to:
(1 == 2) != 3
Operator Precedence and Associativity
Table
• The following tables list the C operator precedence
from highest to lowest and the associativity for each
of the operators:
Precedence Operator Description Associativity

Parentheses (function
()
call)

Array Subscript (Square


[]
Brackets)

1 . Dot Operator Left-to-Right

Structure Pointer
->
Operator

Postfix increment,
++ , —
decrement
Prefix increment,
++ / —
decrement

+/– Unary plus, minus

Logical
!,~ NOT, Bitwise
complement

2 Right-to-Left
(type) Cast Operator

Dereference
*
Operator

& Addressof Operator

Determine size in
sizeof
bytes
Multiplication,
3 *,/,% Left-to-Right
division, modulus

Addition,
4 +/- Left-to-Right
subtraction

Bitwise shift left,


5 << , >> Left-to-Right
Bitwise shift right

Relational less than,


< , <= less than or equal
to
6 Left-to-Right
Relational greater
> , >= than, greater than
or equal to
Relational is equal
7 == , != Left-to-Right
to, is not equal to

8 & Bitwise AND Left-to-Right

Bitwise exclusive
9 ^ Left-to-Right
OR

10 | Bitwise inclusive OR Left-to-Right

11 && Logical AND Left-to-Right

12 || Logical OR Left-to-Right

13 ?: Ternary conditional Right-to-Left

14
= Assignment

Addition,
+= , -= subtraction
assignment

Multiplication,
*= , /=
division assignment
14 Right-to-Left
Modulus, bitwise
%= , &=
AND assignment

Bitwise exclusive,
^= , |= inclusive OR
assignment

Bitwise shift left,


<<=, >>=
right assignment

comma (expression
15 , Left-to-Right
separator)

You might also like