C Foundation

What is C? C Compiler Installation C Extensions C Compiler C Interpreter C Program Structure

C Basics

C Keywords C Data Types C Identifiers C Variables C Constant C Escape Sequences C Constant and Volatile C Typecast

Operators

What is Operator C Comma Operator C Arithmetic Operators C Relational Operators C Logical Operators C Bitwise Operators C Conditional Operators C : : Operator C Operator Priority

Basic IO's

Basic IO's C Formatted Functions C Unformatted Functions C Common Functions

Control Statements

What is Control Statement C if Statement C if else Statement C Nested if Statement C Else if Statement C Break Statement C Continue Statement C Switch Statement C Goto Statement

Looping

What is Control Loop C for Loop C Nested for Loop C while Loop C Nested while Loop C do while Loop C Nested do while loop

Functions

What is Function C User Defined Functions C Recursion C Passing Parameters

Scope

Scope C Local Scope C Global Scope

Storage Classes

What is Storage Class C Auto C Extern C Static C Register

Array

What is Array C One Dimensional Array C Two Dimensional Array C Multi Dimensional Array C Arrays Of Strings

String

What is String C String Functions

Pointer

What is Pointer C Pointers Arithmetic C Pointer to Pointer C Pointers and Arrays C Pointers and Strings C Pointer to Functions Void Pointers Null Pointers C Null and Void Pointer

Structure

What is Structure C Struct within Struct C Array within Structure C Pointer to Structure C Structure and Function C Enum C Bitfield Structure C Type def

Union

What is Union

Files

What is File C read a file C write a file C File Handling C Error Handling C Low Level Disk I/O C Other file functions

Memory Allocation

What is Memory Allocation C Malloc() C Calloc() C Free() C Realloc() C Coreleft()

C Reference

All ASCII Code Basic C Questions

C Interview

C Interview Sets All Star Patterns All Number Patterns All Alphabet Patterns All Series Patterns
The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Operator Precedence In C

Why Operator Precedence?

Every Operator have their own precedence because without operator precedence a complier will conflict with data when performing mathematical calculations.

Example

Consider the following expression 6 - 4 + 8 without operator precedence compiler is helpless to choose which operator needs to execute first. Thus Operator Precedence helps compiler out there.

The following table lists all C operators and their precedence from higher priority to lower priority

Operator Operation Clubbing Priority
( ) Function call Left to Right 1st
[ ] Array " "
Structure Operator " "
. Structure Operator " "
+ Unary plus Right to Left 2nd
- Unary minus " "
++ Increment " "
-- Decrement " "
! Not Operator " "
~ One's Complement " "
* Pointer Operation " "
& Address Operator " "
sizeof Size of an data type " "
(typecast) Type Cast " "
* Multipication Left to Right 3rd
/ Division " "
% Modular Division " "
+ Addition Left to Right 4th
- Subtraction " "
<< Left shift Left to Right 5th
>> Right shift " "
< Less than Left to Right 6th
<= Less than or equal to " "
> Greater than " "
>= Greater than or Equalto " "
= Equality Left to Right 7th
!= InEquality " "
& Bitwise AND Left to Right 8th
^ Bitwise XOR Left to Right 9th
| Bitwise OR Left to Right 10th
&& Logical AND Left to Right 11th
|| Logical OR Left to Right 12th
?: Conditional Operator Right to Left 13th
^=, !=, <<=, > >= Assignment Operator Right to Left 14th
, comma operator Right to Left 15th

Operator precedence program(Easy)

operatorprecedence1.c
#include <stdio.h> //header file section
int main()
{
int a = 2, b = 6, c = 12, d;
d = a + c / b;
printf("The value of d = %d ", d);
return 0;
}
  • The value of d = 4

Note:

/ (Division operator) executed first. Now the expression will be d = a + 2. Finally + (Addition operator) executed and the resultant value 4 is stored in a variable 'd'.

Operator precedence in C(Medium)

operatorprecedence2.c
#include <stdio.h> //header file section
int main()
{
int a = 2, b = 6, c = 12, d;
d = a * b + c / b;
printf("The value of d = %d ", d);
return 0;
}
  • The value of d = 14

Note:

/ (Division operator) executed first. Now the expression is d = a * b + 2. Secondly, * (Multiplication operator) will be executed, now the expresssion becomes d = 12 + 2 Finally + (Addition operator) will be executed and store the value 14 in a variable d.

Operator Precedence in C(Hard)

operatorprecedence3.c
#include <stdio.h> //header file section
int main()
{
int a = 10, b = 10, c = 1, d = 5, r;
r = ++a + (++b) + b-- * (++c) + --d;
printf("The value of r = %d ", r);
return 0;
}
  • The value of r = 48

Note:

  • Step 1: r = 11 + 11 + b-- * 2 + --d
  • Step 2: r = 11 + 11 + 11 * 2 + 4
  • Step 3: r = 11 + 11 + 22 + 4
  • Step 4: r = 48.
  • Report Us

    We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

    Report

    We to update you