C-Language Basic learning operator-assignment operator

Source: Internet
Author: User

Simple assignment

In the C language, operator = does not represent equality, but an assignment operator. This means that the left side of the symbol = is a modifiable variable name, and the right is the value assigned to the variable.

The following program statements:

i = i+1;  

Mathematically, the equation is not tenable. As an assignment statement for C, it means finding the value of the assignment symbol = right variable i, plus 1 and then assigning the variable with the left name I. On the right side of the assignment operator = If there is a variable name, it is best that the variable name is already initialized.

Different compilers have different settings for the values of uninitialized variables, some are 0, some are random numbers, and some are directly error-aware.

Compound assignment

The arithmetic operator +,-,*,%,/and the assignment operator = combine to form a compound assignment operator, as follows:

+ =: Add Assignment Operator Example: i + = 1 equivalent to i = i + 1
-=: Minus assignment Operator Example: i-= 1 equivalent to i = i-1
*=: Multiply assignment Operator Example: I *= 1 equivalent to i = i * 1
%=: Example of an assignment operator: I%= 1 equivalent to i = i% 1
/=: Except assignment operator Example: I/= 1 is equivalent to i = I/1

To give a simple example:

#include <stdio.h>  int main (void)  {      int9;          // Add      1 to the value of variable a by using compound assignment // write down your code      here. 1 ;      printf ("A's value is%d\n", a);            return 0 ;  }  

More learning content, just in the code bud Net Http://www.mayacoder.com/lesson/index

The result is certainly obvious:

C-Language Basic learning operator-assignment operator

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.