Ahad, 16 Januari 2011

AGAIN..BASIC PROGRAM EXERCISE
Cube jawab soalan dibawah.. ada byk lagi yang sedang menanti.. :)

1. Describe the two ways to include comments in a C++ program.


2. What is wrong with this program?
#include
int main()
{
//”luving C++:”
cout<<”I luv C++\n” }


3. What is wrong with the following C-style comment?
cout<<”Hello, /*change*/ world.\n”;

4. What does a declaration do?

5. What is the shortest possible C++ program?

6. Where the name “C++” does comes from?

7. What’s wrong with these declarations:
int first = 67, last = 100, new = 2, old = 6;

8. In each of the following, assume that m has the value 5 and n has the value 2 before the statement executes. Tell what the values of m and n will be after each of the following statements executes:
a. m*=n++;
b. m+=--n;


9. What is a run-time error? Give examples of two different kinds of run-time errors.


10. What is a compile-time error? Give examples of two different kinds of compile-time errors.

answer:
1. i. /* like this */
ii. //like this

2. The semicolon is missing from the last statement

3. Everything between the double quotes will be printed, including the intended comment

4. A declaration tells the compiler the name and type of the variable being declared. It also may be initialized in the declaration.


5. void main(){}

6. The name refers to the C language and its increment operator ++. The name suggests that C++ is an advance over C.

7. the only thing wrong with these declarations is that new is a keyword. Keywords are reserved and cannot be used for names of variables.

8. a. m will be 10 and n will be 1
b. m will be 6 and n will be 1


9. A run time error is an error that occurs when a program is running. Numeric overflow and division by zero are examples of run time errors.

10. A compile-time error is an error that occurs when a program is being compiled. Examples: syntax errors such as omitting a required semicolon, using an undeclared variable, using a keyword for the name of a variable.




Tiada ulasan:

Catat Ulasan