Assignment: Constants, Variables, and Data Types
in C
Section A: True / False
1. Any valid printable ASCII character can be used in an identifier.
2. All variables must be given a type when they are declared.
3. Declarations can appear anywhere in a program.
4. ANSI C treats the variable name name and Name to be the same.
5. The underscore character (_) can be used anywhere in an identifier.
6. The keyword void is a data type in C.
7. Floating■point constants, by default, denote float type values.
8. Like variables, constants have a type.
9. Character constants are coded using double quotes.
10. Initialization is the process of assigning a value to a variable at the time of declaration.
11. All static variables are automatically initialized to zero.
12. The scanf function can be used to read only one value at a time.
Section B: Fill in the Blanks
a) The keyword ______ can be used to create a data type identifier.
b) ______ is the largest value that an unsigned short int type variable can store.
c) A global variable is also known as ______ variable.
d) A variable can be made constant by declaring it with the qualifier ______ at the time of
initialization.
Section C: Short■Answer / Definition Questions
1. What are trigraph characters? How are they useful?
2. Describe the four basic data types in C. What kinds of values can they represent?
3. What is an unsigned integer constant? What is the significance of declaring a constant unsigned?
4. Describe the characteristics and purpose of escape sequence characters.
5. What is a variable, and what is meant by the 'value' of a variable?
6. How do variables and symbolic names differ?
7. State the differences between declaration of a variable and definition of a symbolic name.
8. What is initialization? Why is it important?
9. What qualifiers can an int have, at a time?
10. A programmer would like to use the word DPR to declare all the double■precision floating point
values in his program. How could he achieve this?
11. What are enumeration variables? How are they declared? What is the advantage of using them
in a program?
12. Describe the purpose of the qualifiers const and volatile.
13. When dealing with very small or very large numbers, what steps would you take to improve the
accuracy of the calculations?
Section D: Validity, Errors, and Examples
1. Which of the following are invalid constants, and why? 0.0001, 5 × 1.5, 99999, +100, 75.45 E■2,
"15.75", ■45.6, ■1.79 e + 4, 0.00001234
2. Which of the following are invalid variable names and why? Minimum, [Link], n1+n2,
&name;, doubles, 3rd_row, n$, Row Total, floatSum, Column■total
3. Find errors, if any, in the following declaration statements. Correct them:
Int x; float letter,DIGIT; double = p,q; exponent alpha,beta; m,n,z: INTEGER short char c; long int
m; count; long float temp;
4. What would be the value of x after execution of the following statements?
int x, y = 10; char z = 'a'; x = y + z;
5. Identify syntax errors in the following program. After corrections, what output would you expect
when you execute it?
Section E: Programming Tasks
1. Write a program that will print a conversion table from Fahrenheit to Celsius. Use symbolic
constants to define minimum value, maximum value, and step size.
2. Write a program to output the following multiplication table (for 5).
3. Given the radius of a circle, write a program to compute and display its area. Use a symbolic
constant to define π (pi) and assume a suitable value for radius.
4. Given two integers, 20 and 10, write a program that uses a function add() to add the two numbers
and sub() to subtract the two numbers; then display the sum and difference.
5. Given the values of three variables a, b, c, write a program to compute and display the value of x
= a / (b − c). Execute for: (a=250, b=85, c=25) and (a=300, b=70, c=70). Comment on output.
Section F: Formula & Relationship
The relationship between Celsius (C) and Fahrenheit (F) is given by the formula:
F = (9C / 5) + 32
Write a program to convert temperature from Celsius to Fahrenheit.