C Programming constants and variables | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Thursday, March 28, 2019

C Programming constants and variables | My CS Tutorial

C programming constants and variables



In this post we will know today what are constants and variables in C language, how many types are there and what are the rules for writing them. So let's start ..

C Constants | My CS Tutorial

Constant

Characters, numbers, and special symbols, when properly formed, form constants, variable and keywords.
"A constant is a quantity that does not vary.This amount can be stored at some place in the computer's memory."
               C constants can be divided into two major categories:
  1. Primary constants
  2. Secondary constants

Primary consonants:

Integer,real,character consonant

Secondary consonant:

Array,pointer, structure, union, enum.etc

At this stage we will limit our discussion to only the primary constants integer, real and character constants.

Rules for Integer Constants

  • The integer constant should have at least one digit.
  • It should not have a decimal point.
  • It can be positive or negative.
  • If a signal does not increase the integer constant, then it is considered positive.
  • No commas or spaces are allowed inside the integer constants.
  • Acceptable range for the integer constant is -32768 to 32767.
Actually, the boundary of the integer constant depends on the word size of the computer. The limit for 16-bit computers will be -32678 to 32767.For 32 bit computer the range would be much larger.
Ex.: 625
      -7605

Rules for Real Constants

The real constants are often called floating point constants.
  • The real constant should have at least one digit.
  • It must have a decimal point.
  • It can be positive or negative.
  • If a signal does not increase the integer constant, then it is considered positive.
  • No commas or spaces are allowed inside the integer constants.
Ex.: +453.67
        -47.7865

Rules for Character Constants

  • A character constant is a single alphabet, single digit, or a single special symbol, which is enclosed within a single inverted commas, both inverted commas should be placed on the left side.
  • The maximum length of a character constant can be 1 character.
Ex.: 'B'
        '8'
        '='

C variables

In C language, the amount that can change during program execution is called a variable.Variable names are names given for location in memory of computer where different constants are stored. In these places, the integer, the real or the characters can be fixed. In any language, types of variables that can support it can depend on the types of continuous that can handle.
Ex.: real variable name  must be real constant.

Rules for Variables Names

  • Variable name is a combination of alphabet, number or underscores.
  • The first character of a variable name should be an alphabet.
  • No spaces or commas are allowed in any variable name.
  • Only a special symbol is used in the variable name which is underscores  ( _ ).

So friends Today we have known what constants and variables are, how many types are and how they are used. I understand that you have understood all easily. If you have any issues please comment me directly. Also read my second post.Thanks

No comments:

Post a Comment