Share
Explore BrainMass

Constant and Variable in a Program

1. What is a data type in C? Describe two data types and how they might be used in a C program.

2. What is the difference between a constant and a variable in a program? Why would you use one or the other?

Solution Preview

1. A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in his program. These are data types. In C language, data types can be broadly classified as Primary data type, Derived data type and User-defined data type. Primary data type are fundamental data types, contains int, char, float, and double. int is used to define integer numbers. char defines characters. float is used to define floating point numbers. Double is used to define BIG floating point numbers and it reserves twice the storage for the number.
Derived data types defined by the system include pointer and array. User defined data types are built on existing types. These include typedef and enumerations.

Integer Type: Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer ...

Solution Summary

This solution discusses data types in C and the differences between constants and variables in a program.

$2.19