Programming Essentials in C: Chapter 2 Assignment (CLA) Exam Answers

1. Which of the following strings is a proper integer number (in the “C” language sense)?

  • 123456
  • 123_456
  • 123.456
  • 123,456

2. What is the value of the following integer literal?

08
  • the literal is invalid
  • 10
  • 1000
  • 8

3. What is the value of the following integer literal?

0x8
  • the literal is invalid
  • 10
  • 1000
  • 8

4. Which of the following strings is a valid variable name?

  • Monte_Carlo
  • Monte Carlo
  • Monte@Carlo
  • Monte-Carlo

5. Which of the following strings is an invalid variable name?

  • _0_
  • _0
  • 0_
  • ___

6. Is the following declaration valid?

int var, var;
  • Yes
  • No

7. What is the value of the var variable at the end of the following snippet?

    int var;
    var = 2;
    var = var * var;
    var = var + var;
    var = var / var;
    var = var % var;
  • 16
  • 8
  • 1
  • 0

8. What is the value of the var variable at the end of the following snippet?

    int var;
    var = 2;
    var = var * var;
    var = var + var;
     /*
    var = var / var;
    var = var % var;
      */
  • 16
  • 1
  • 8
  • 0

9. Which of the following strings is a proper floating-point number (in the ”C” language sense)?

  • 123_456
  • 123456
  • 123,456
  • 123.456

10. What is the value of the following floating-point literal?

8765E-2
  • 876.5
  • 8.765
  • 0.8765
  • 87.65

11. What is the value of the x variable at the end of the following snippet?

int x;
x = 1 / 2;
  • 0.5
  • 1
  • 0
  • 2

12. What is the value of the x variable at the end of the following snippet?

int x;
x = 1 / 2 * 3;
/***
  • 0
  • 1.5
  • 1
  • 2

13. What is the value of the x variable at the end of the following snippet?

float x;
x = 1. / 2 * 3;
/***
  • 2
  • 1.5
  • 1
  • 0

14. What is the value of the k variable at the end of the following snippet?

    int i,j,k;

    i = 4; 
    j = 5;
    --i;
    k = i * j;
  • 12
  • 18
  • 16
  • 15

15. What is the value of the k variable at the end of the following snippet?

    int i,j,k; 

    i = 4; 
    j = 5;
    ++j; 
    k = i * j;
  • 21
  • 24
  • 28
  • 18

16. What is the value of the k variable at the end of the following snippet?

int i,j,k;

 i = 3; 
 j = -3; 
 k = i * j; 
 k += j; 
 k /= i;
  • -4
  • 8
  • 8
  • 4

17. What is the value of the c variable at the end of the following snippet?

char c;

c = '\';
  • \0
  • the assignment is invalid and causes a compilation error
  • \

18. What is the value of the c variable at the end of the following snippet?

    char c;

    c = 'a';
    c -= ' ';
  • a
  • A
  • \0
  • the assignment is invalid and causes a compilation error

19. What is the value of the k variable at the end of the following snippet?

    int i,j,k; 
    
    i = 3; 
    j = -3; 
    k = (i >= i) + (j <= j) + (i == j) + (i > j);
  • 2
  • 3
  • 0
  • 1

20. What happens if you try to compile and run this program?

    #include  
    int main(void) { 
        int i,j,k; 
        i = 2; 
        j = -2; 
        if(i) 
            i--; 
        if(j) 
            j++; 
        k = i * j; 
        printf("%d",k); 
        return 0; 
    }
  • -1
  • 2
  • 1
  • -2
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x