variable in C

Data values are kept in variables as storage.There are various sorts of variables in C.

For instance

  • Integers (whole numbers) without decimals, such as 91 or -13, are stored in integer variables specified with the keyword int.
  • Floating point numbers with decimals, such as 99.98 or -1.23, are stored in floating point variables specified using the keyword float.
  • Single characters, such “A” or “z,” are stored in character variables specified with the keyword char. Char values must be enclosed in single quotation marks.

Declaration

  • A variable cannot be declared without its data type being mentioned. What we want to put in the variable and how much space we need it to hold will determine the data type of the variable. Declaring a variable has the following basic syntax:

data_type  variable_name;

Identifying a Variable

  • Anything can be referred to as a variable. However, there are several guidelines we must adhere to while naming a variable:
  • Only alphabetic characters, numbers, and underscores (_) are permitted in variable names.
  • A digit cannot begin a variable.
  • A variable’s name cannot contain any white space.
  • No special characters or reserved keywords should be present in the name.

Variables can have their names changed or their values modified, but their types cannot be changed in the same ways. If a variable is of the integer type, then a programme can only store integer values in it. An integer variable cannot take a value of the character type. Even a decimal value cannot be stored in an integer variable.

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in