Thursday, September 11, 2008

C Assignment # 3

C Assignment # 3

1. A C program contains the following declarations:
int i = 8, j = 5;
float x = 0.005, y = -0.01;
char c = 'c', d = 'd';

Determine the value of each of the following expressions. Use the values initially assigned to the variables for each expression.
(a) -(i + j)
(b) ++x
(c) c == 99
(d) y--
(e) --j
(f) j != 6
(g) 2 * x + ( y == 0)
(h) !(c == 99)
(i) (i > 0) && (j < 5)
(j) (i > 0) || (j < 5)
(k) i += 2
(l) j -= 3
(m) i = j = 6

2. Explain the use of the getchar() and the putchar() function in C.

3. Write a program in C to read in a line of lower-case text and convert it into upper-case text. Use the getchar() and putchar() functions. Assume that the line is terminated by the newline ('\n') character.

4. What is the purpose of the scanf() function? What is the purpose of the control string in a scanf() function? What is the use of the ampersand symbol in scanf()? If & symbol is not used with a variable in scanf() will it result in a syntax error?

5. What is the purpose of the printf() function? In printf() function, must the variable names be preceded by the ampersand function?

No comments: