Google News
logo
Embedded C - Interview Questions
What do you understand by the pre-decrement and post-decrement operators?
The Pre-decrement operator (--operand) is used for decrementing the value of the variable by 1 before assigning the variable value.
#include < stdio.h >  
int main(){  
    int x = 100, y;  
  
    y = --x;   //pre-decrememt operators  -- first decrements the value and then it is assigned 

    printf("y = %d\n", y);  // Prints 99
    printf("x = %d\n", x);  // Prints 99
    return 0;  
}  
The Post-decrement operator (operand--) is used for decrementing the value of a variable by 1 after assigning the variable value.
#include < stdio.h >  
int main(){  
    int x = 100, y;  
  
    y = x--;   //post-decrememt operators  -- first assigns the value and then it is decremented 

    printf("y = %d\n", y);  // Prints 100
    printf("x = %d\n", x);  // Prints 99
    return 0;  
}
Advertisement