Click here to Skip to main content
15,887,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Attempting to get a better understanding of types of data for homework project. I understand that a variable changes and constant remains the same but how do they relate to data types char, int, double, string, and date?

Thanks, So these data types char, int, double, string, and date are utilized based on the type data defined in the program?
Posted
Updated 25-Mar-10 17:09pm
v2

Variables and constants have types of char, int, double, string, and date. Constants are just variables that can only be assigned a value once. That range of acceptable values for that constant or variable depends on the data type. So, a variable of data type "double" can have a numeric value, such as 1.4. That same variable could then be reassigned a new value of, say, 20.9. A constant of data type "string" could be assigned a value of "hello world". That would be it's value during the entire time the program is running (i.e., you couldn't change the value to "hello Earth"). If it were a variable (instead of constant) of data type string, you could change the value as often as you want.
 
Share this answer
 
Tahir heres a story that might help u whats a datatype

All ur family members can make use of all the resources of ur house but ur friend cant DIRECTLY come and start making use of resources he has to take ur permission for that similarly in programming we have datatypes that are used for type saftey we have set of datatypes such as int,float,double,char,string

now if i initialize an integer variable say int x=10;
then in this case variable x will hold only an integer value this is the restriction imposed on x if u try to store string value in x which is an integer type variable u will end up in an error of incompatible type.

Variables are used to store values which are stored in the computers memory, computer memory are very tedious to remember so we declare a human understandable character or word say in this case
int x[where x is an variable which will hold an integer value]

variables can change their values depending upon the code thats called overriding try this code for better understanding

C#
class Example1
{
public static void main(String[ ] args)
{
int x = 10;

System.out.println("value of x before overriding: "+x);
int y =20;
x=x+y;
System.out.println("value of x after overriding: "+x);
}
}


now constants are those variables which do not change their values from start of the program till the end and any attempt to change the value of a constant will throw an error.
In the above story i said ur friend has to take ur permission for using the resources well Tahir sometimes variables have to be typecasted in order to get the desired result u will learn about type casting in the further chapters of ur programming............

Thanks & Regards
Radix :rose:

Do rate my answer once u find it usefull
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900