What are variables and it what way is it different from constants?

0 like 0 dislike
asked May 12, 2018 in General by Tarunjaiswal (100 points)

Variables and constants may at first look similar in a sense that both are identifiers made up of one character or more characters (letters, numbers and a few allowable symbols). Both will also hold a particular value.  Values held by a variable can be altered throughout the program, and can be used in most operations and computations. Constants are given values at one time only, placed at the beginning of a program. This value is not altered in the program. For example, you can assigned a constant named PI and give it a value 3.1415  .  You can then use it as PI in the program, instead of having to write 3.1415 each time you need it. 

commented Jan 19, 2020 by StevHady
Efectos Del Viagra A Largo Plazo Viagra Cialis Foren  <a href=http://cialibuy.com>cialis 40 mg</a> Dog Excessive Drooling Keflex Viagra Preiswert Levitra Acheter En Baisse
commented Dec 20, 2020 by Sciemia
Viagra Generico Cialis  ignistinilla <a href=https://bansocialism.com/>cheapest cialis online</a> esottCam cialis generique pharmacie en ligne
commented Apr 3 by Sciemia
https://gcialisk.com/ - cialis online
commented Apr 16 by MyronSmump
online dating service  
<a href=http://freedatingsitesus.com/?>personals free  </a>
commented 4 days ago by embancy
commented 4 days ago by Javiernub
tinder online , tinder sign up  
<a href=http://tinderentrar.com/?>tinder website </a>

1 Answer

0 like 0 dislike
answered May 21, 2018 by MayankSingh (33 points)

Variables

If you declare a variable in C (later on we talk about how to do this), you ask the operating system for a piece of memory. This piece of memory you give a name and you can store something in that piece of memory (for later use). There are two basic kinds of variables in C which are numeric and character.

Numeric variables

Numeric variables can either be of the type integer (int) or of the type real (float). Integer (int) values are whole numbers (like 10 or -10). Real (float) values can have a decimal point in them. (Like 1.23 or -20.123).

Character variables

Character variables are letters of the alphabet, ASCII characters or numbers 0-9. If you declare a character variable you must always put the character between single quotes (like so ‘A’ ). So remember a number without single quotes is not the same as a character with single quotes.

Constants

The difference between variables and constants is that variables can change their value at any time but constants can never change their value. (The constants value is lockedfor the duration of the program). Constants can be very useful, Pi for instance is a good example to declare as a constant.

Make sure your Question & Answer should be appropriate and useful to the reader. Don't just copy and paste content from other sources.
...