Puzzle E16

Precedence of Arithmetic Operators

highest precedence: ()
high precedence:    *  /  %
medium precedence:  +  -
low precedence:     = 

During evaluation, operations are performed in order of precedence from high to low. If there are several arithmetic operators of the same precedence, they are performed left to right.

Assignment has low priority. If there are several assignment opertors in an expression, they are performed right to left.

What is displayed by this program?

#include <stdio.h>

/* Puzzle E16 -- precedence of arithmetic operators */
int main()
{
  int a = 1, b = 2 ;
  int result;
  
  result = a/b + a/b;
  
  printf("result: %d\n", result );   
  return 0;
}


Previous Page        Answer         Next Page         Home