CPA Chapter 2 Assessment Answers 100%

Last Updated on October 18, 2019 by Admin

CPA Chapter 2 Assessment Answers 100%

  1. What is the output of the following snippet?

    int i = 0, j = i++, k = –i;
    if(i > 0)
    j++;
    else
    k++;
    if(k == 0)
    i++;
    else if(k > 0)
    k–;
    else
    k++;
    cout << i * j * k;

    • 0
    • -1
    • 2
    • 1
  2. What is the output of the following snippet?

    int i = 1, j = i++, k = –i;
    if(i > 0) {
    j++;
    k++;
    }
    else {
    k++;
    i++;
    }
    if(k == 0) {
    i++;
    j++;
    }
    else {
    if(k > 0)
    k–;
    else
    k++;
    i++;
    }
    cout << i * j * k;

    • 2
    • 4
    • 8
    • 0
  3. What is the output of the following snippet?

    double big = 1e15;
    double small = 1e-15;

    cout << fixed << big + small;

    • 0.0
    • 1000000000000000.000000
    • 1.01e15
    • 1000000000000000.0000000000000001
  4. What is the output of the following snippet?

    bool yes = !false;
    bool no = !yes;
    if(!no)
    cout << “true”;
    else
    cout << “false” ;

    • not
    • yes
    • true
    • false
  5. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int i = 5, j = 0;
    while(i > 0) {
    i–;
    j++;
    }
    cout << j;
    return 0;
    }

    • 4
    • 5
    • 2
    • 3
  6. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int i = 3, j = 0;
    do {
    i–;
    j++;
    } while(i >= 0);
    cout << j;
    return 0;
    }

    • 4
    • 2
    • 3
    • 5
  7. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    float val = 100.0;
    do {
    val = val / 5;
    cout << “*”;
    } while(val > 1.0);
    return 0;
    }

    • **
    • ***
    • *****
    • ****
  8. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    for(float val = -10.0; val < 100.0; val = -val * 2)
    cout << “*”;
    return 0;
    }

    • ***
    • ****
    • *****
    • **
  9. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    for(float val = -10.0; val < 100.0; val = -val * 2) {
    if(val < 0 && -val >= 40)
    break;
    cout << “*”;
    }
    return 0;
    }

    • ****
    • **
    • *****
    • ***
  10. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int a = 1, b = 2;
    int c = a | b;
    int d = c & a;
    int e = d ^ 0;
    cout << e << d << c;
    return 0;
    }

    • 113
    • 100
    • 131
    • 031
  11. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int a = 1, b = 2;
    int c = a << b;
    int d = 1 << c;
    int e = d >> d;
    cout << e;
    return 0;
    }

    • 2
    • 0
    • 4
    • 1
  12. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int a = 2;
    switch(a << a) {
    case 8 : a++;
    case 4 : a++;
    case 2 : break;
    case 1 : a–;
    }
    cout << a;
    return 0;
    }

    • 3
    • 2
    • 5
    • 4
  13. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int t[] = { 8, 4, 3, 2, 1 }, i;
    for(i = t[4]; i < t[0]; i++)
    t[i – 1] = -t[3];
    cout << i;
    return 0;
    }

    • 4
    • 3
    • 2
    • 5
  14. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    bool t[5];
    for(int i = 0; i < 5; i++)
    t[4 – i] = !(i % 2);
    cout << t[0] && t[2];
    return 0;
    }

    • true
    • 0
    • 1
    • false
  15. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int a[] = {4, 0, 3, 1, 2};
    int b[] = {1, 2, 3, 4, 5};

    for(int i = 0; i < 5; i++)
    b[a[i]] = b[4 – i];
    cout << b[0] << b[4];
    return 0;
    }

    • 54
    • 15
    • 45
    • 51
  16. What is the output of the following snippet?

    #include <iostream>
    using namespace std;
    int main() {
    int g[3][3] = {{2, 4, 8}, {3, 6, 9}, {5, 10, 15}};
    for(int i = 2; i >= 0; i–)
    for(int j = 0; j < 3; j++)
    g[i][j] += g[j][i];
    cout << g[1][1];
    return 0;
    }

    • 9
    • 12
    • 6
    • 15
  17. What is the output of the following snippet?

    #include <iostream>
    using namespace std;

    struct str {
    int t[3];
    char s[3];
    };

    int main() {
    str a = { 1, 2, 3, ‘a’, ‘b’, ‘c’ };
    str b = { 5, 6, 7, ‘x’, ‘y’, ‘z’ };
    cout << char(b.s[0] + a.t[0]) << int(a.s[2] – a.s[0]) << int(b.s[2] – b.s[1]);
    return 0;
    }

    • z22
    • a11
    • y21
    • b12
  18. What is the output of the following snippet?

    #include <iostream>
    using namespace std;

    struct str {
    int t[3];
    char s[3];
    };

    int main() {
    str z[3];
    for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++) {
    z[i].s[j] = ‘0’ + i + j;
    z[j].t[i] = i + j;
    }
    cout << z[0].s[1] << z[1].t[2] << z[2].s[0];
    return 0;
    }

    • 312
    • 032
    • 123
    • 132
  19. What is the output of the following snippet?

    #include <iostream>
    using namespace std;

    struct sct {
    int t[2];
    };

    struct str {
    sct t[2];
    };

    int main() {
    str t[2] = { {0, 2, 4, 6}, {1, 3, 5, 7} };
    cout << t[1].t[0].t[1] << t[0].t[1].t[0];
    return 0;
    }

    • 43
    • 34
    • 52
    • 25
  20. What is the output of the following snippet?

    #include <iostream>
    using namespace std;

    int main() {
    char arr[5] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’ };
    for(int i = 1; i < 5; i++) {
    cout << “*”;
    if((arr[i] – arr[i – 1]) % 2)
    continue;
    cout << “*”;
    }
    return 0;
    }

    • ******
    • *******
    • *****
    • ****