[C language] variables vs constants

Source: Internet
Author: User

--------------------------------------------------------------------------------

1. Fixed number is constant, directly written in the program called Direct volume (literal).

int total = 100-price;

#include <stdio.sh>int  main () {  int0; Initialize  printf (" Please enter amount:");  scanf ("%d", &price);     // Take Care not to forget to take the address symbol  int  -Price ;  printf (" Find you%d Yuan ", change);    }

2. We do not know what the above 100 is, and to make it easier for us to identify it, a constant is used here.

The const modifier multibyte is used before int to denote constants, attributes defined with const, and cannot be modified once initialized (PHP5); If you modify the constants to assign values, the compiler will error (read-only variable is not assignable) and use uppercase for the constant conventions.

   

const int AMOUNT = 100;

int change = Amount-price;

Const int  - ;     int 0 ;        printf (" Please enter amount:");     scanf ("%d", &price);        int change = AMOUNT-Price ;        printf (" find you%d dollars "

3. If you do not want to define constants now, use multiple scanf

  

intamount; Not initializedintPrice;
/*
printf ("Please enter two integers:");
scanf ("%d%d", &amount, &price); Two numbers are separated by a space or carriage return; Note: When you encounter a non-numeric input such as a string, scanf will make an error, whatever is in memory
printf ("%d +%d =%d", amount, price, amount + price);
*/
Prinf ("Please enter the coupon:"); scanf ("%d", &amount);p rintf ("Please enter the amount:"); scanf ("%d", &Price );intChange = Amount-price;printf ("find you%d dollars", change);

@ Black eyed poet <www.chenwei.ws>

[C language] variables vs constants

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.