Assignment Operators and Combined Assignment Operators - C Language Basics

C examples for Language Basics:Variable

Introduction

The assignment operator = assigns a value to a variable.

Demo Code

#include <stdio.h>
int main(void) {

    float x = 3 + 2;
}

These operations can be shortened with the combined assignment operators.

Demo Code

#include <stdio.h>
int main(void) {
    int x = 0;/*from w w w  . j a  v a  2 s .c  om*/
    x += 5; /* x = x+5; */
    x -= 5; /* x = x-5; */
    x *= 5; /* x = x*5; */
    x /= 5; /* x = x/5; */
    x %= 5; /* x = x%5; */
}

Related Tutorials