Basic data types for C language Basics-variables and constants

Source: Internet
Author: User

Variables and constants



You must declare a variable before using the variable. The syntax for a variable definition is:

For example, we can define an integer variable like this:

int A; int type denotes integral type

To declare multiple variables, you can declare them individually, or you can add multiple variable names after the data type name, separated by commas:

Data type name variable name 1, variable name 2, variable name 3;

You can assign a value to a variable while creating it, that is, initializing the variable. The syntax is:

Data type name Variable name = value;


It is a good idea to initialize variables when creating variables. This is because some compilers initialize to 0 by default, and some compilers perform operations such as output or arithmetic if the variables are not initialized, and the results you get will be random.


The definition of a constant, add a const keyword before the variable definition:

Const data type name Variable name = value;

When declaring constants, remember to initialize them, because constants can be assigned only when they are initialized, and in other cases assignments are not allowed. Once a constant is initialized, its value cannot be changed.

Try the knife, code the C language variables and constants.

#include <stdio.h> int main (void) {//Create an integer variable A, initialize to 1//create an integer constant Max, initialize to 100//write down your code int here      A = 1;      const int MAX = 100;       printf ("a=%d, max=%d", A, MAX);  return 0; }

Learn more about the code Bud NET, Http://www.mayacoder.com/lesson/index

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/85/DE/wKioL1etKaexY4OVAAAO_l6kxUw029.png-wh_500x0-wm_3 -wmp_4-s_2257600308.png "title=" 2.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px; height:230px; "alt=" Wkiol1etkaexy4ovaaao_l6kxuw029.png-wh_50 "/>


Basic data types for C language Basics-variables and 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.