Chapter 9
Exploring C Programming Language
Exercises :
1. Fill in the blanks.
a. Identifiers in C programming language start with ………….
b. break is a keyword in C ……………… (TRUE/FALSE)
c. A variable in C can store more than one value at a time………. (TRUE/FALSE)
d. An integer variable typically reserves………….. bytes in memory.
e. Built-in function used to accept user input from the keyboard is …………….
f. Format specifier for accepting value from keyboard for an integer variable is …………..
g. Every operator in C requires exactly two operands …………. (TRUE/FALSE)
h. ……………….. sign is used to indicate reminder operation in C.
i. To compare two float variables in C, we can use ………. Statement.
j. When we need to select a set of statements for execution in a C program based on some integral value, a good choice can be to use ………… construct.
2. Short answer questions:
a. If we need to execute many statements when an if condition in C returns true, how can we write them? Write a code segment.
b. List five commonly used operators of C programming language with their meaning.
c. The scanf statement should always be preceded by a printf statement in C. Is it true? Explain briefly.
3. Programming assignments:
a. Write a C program and try to declare variables of type int with the following Name Separately
first variable, second Variable, Third Variable, char, number, x, 9months, blp24, 8724, dimatala, gogamukh??, I want to be a doctor Report if any variable declarations are not permitted by the compiler. Analyze the reasons
(Hint: refer Section 9.1).
b Wine the following code segment inside the main function of a C program and run it Analyse the output. Relate the output with the concepts learned in Section 9.2 about the allocated space of a variable in computer memory.
int var = 7;
printf(The value of var is %d.”, var);
printf(“The address of var in memory is %p.”, &var);
c. Write the following code segment inside the main() function of a C program and run it. Analyse the output. Relate the output with the concepts learned in Section 9.2 about the allocated space of a variable in computer memory.
int p = 9;
printf(“Size of the variable p is %ld \n”, sizeof(p));
printf(“Size of an integer is %ld \n”, sizeof(int));
printf(“Storage for the type of the variable p is %ld \n”, sizeof( typeof(p) ) );
d. Write a C program to do the following.
i. Declare three integer variables as int p = 9, q= 7, result = 0;
ii. Display the value of the result variable after performing the following operations and storing the output of each operation in it.
p+q; p-q; p/q; p q: p % q; p+q; (p & q); (p && q); iii. Perform ++result; result++; result Display value of result at each step.
e Write a C program to find the area of a rectangle. The length and width of the rectangle are inputs.
f. Change the programming example B.I to accept the integers from the keyboard using scanf() function.
g. Improve the programming example B.5 to check whether the student scores PASS or FAIL in individual subjects [Hint: use if clause).
h. Improve the programming example B.5 to check whether every mark entered from the keyboard is positive or not. If any mark is wrongly entered as negative, prompt the use to re-enter. (Hint: use if clause and then put scanf()].
i. Write a program in C for awarding student grade (as example B.5) using switch-case construct.