You are on page 1of 3

Thareja: Object Oriented Programming with C++

SOLUTIONS TO DEBUGGING EXERCISES (Find the output and


Find the error questions)

CHAPTER 2: BASICS OF C++ PROGRAMMING

Find the output of the following codes

1. a = ‐28
b = ‐31

2. a = 68

3. a =0

4. The value of the expression a + b /c ‐ d * e = ‐


19 The value of the expression (a + b) /c ‐ d *
e = ‐19 The value of the expression a +( b / (c
‐ d)) * e = ‐9

5. 0
1
1
1

6. 10 + a / 4 * b = 35
c / d * b + a – b = 20

7. The program will show garbage values as a and b are not initialized.

8. 70

9. n = 0

10. c = 33.00000

11. a = 3 b = 4

12. 0

13. a = 9

14. 4 9 0

© Oxford University Press. All rights reserved.


Thareja: Object Oriented Programming with C++

SOLUTIONS TO DEBUGGING EXERCISES (Find the output and


Find the error questions)
15. 3 4 4

16. 3 1 7

17. Enter any four digit number : 6666


Enter any floating point number : 7.0
The numbers are : 6666 7.0

18. Enter three characters : a b c a = b b = c c = d

19. x = 12 y = 22 RESULT = 64

20. x = 11 y = 20 RESULT = 30

21. 0
0.666667
2

22. 16

23. 0

24. n =2

25. c=2d=4

26. _ = 30

27. Error – lvalue required

28.
a*b=6
a/b=0
a%b=2
a && b = 2

29. a= 0

30. a=0

31.
num = 56
num = 70
num = 38

© Oxford University Press. All rights reserved.


Thareja: Object Oriented Programming with C++

SOLUTIONS TO DEBUGGING EXERCISES (Find the output and


Find the error questions)
Find the error in the following codes

1. variable b is not declared

2. int a = 4 ); There should be no round bracket here

3. ++a++ is not allowed

4. lvalue required. Increment operator cannot be applied to a numeric constant. It can be applied on
variable

Find errors in the following declaration statements

1. Int n; // small I in int


2. float a b; // comma between a and b
3. double = a, b; // no equal sign between double and a
4. complex a b; // complex is not a data type in C
5. a,b : INTEGER // it should be int a, b;
6. long int a;b; // long int a,b

© Oxford University Press. All rights reserved.

You might also like