Explore BrainMass

Constant and Variable in a Program

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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?

© BrainMass Inc. brainmass.com October 24, 2018, 11:55 pm ad1c9bdddf

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.

See Also This Related BrainMass Solution

Legal Java variable names and a Basic Program.

This program calculates profits and sales prices for a furniture company.

-First calculate the profit, then calculate the sales price, then calculate the profit when the sale price used.

-Profit is defined as the retail price minus the wholesale price.

-The sales price 20% deducted from the retail price.

-The sales profit is defined as the sales price minus the wholesale price.

-Perform the appropriate calculations for the assignment statement.

View Full Posting Details