C Essentials – Part 1: SUMMARY TEST

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

    #include <stdio.h>
    int main(void)
    {
       int i, t[4];
    
       t[3] = 0;
    
       for(i = 1; i >= 0; i--)
          t[i] = t[3] * i;
       printf("%d", t[1]);
       return 0;
    }
    • the program outputs 0
    • the program outputs 1
    • the program outputs 2
    • the program outputs 3
  2. What happens if you try to compile and run program?

    #include <stdio.h>
    int main(void)
    {
       int* a, b;
       b = 1;
       a = &b;
       b = 2;
          
           printf("%d\n", b);
       printf("%d", *a);
       return 0;
    }
    • 2
      2
    • 1
      2
    • 1
      1
    • 2
      1
  3. What happens if you try to compile and run program?

    #include <stdio.h>
    int main(void)
    {
       int i, j;
       i = 1; j = 1;
    
      while(i > 16) {
          i += 4;
          j++;
      }
       printf("%d", j);
       return 0;
    }
    • the program outputs 1
    • the program outputs 5
    • the program outputs 0
    • the program outputs 4
  4. What is the value of the following integer literal?

    013
    • 11
    • 13
    • 19
    • the literal is invalid
  5. What happens if you try to compile and run program?

    #include <stdio.h>
    int fun(){
       int a;
       return ++a;
    }  
    int main()
    {
       printf("%d", fun());
       return 0;
    }
    • the program outputs 1
    • the program outputs 0
    • the program outputs a
    • the program causes an error
  6. What is the value of the var variable at the end of the following snippet?

    int var;
    var = 3;
    var = var * var;
    /* var = var + var; */
    /*
    var = var / var;
    var = var % var;
    */
    var = var - 1;
    • 8
    • 9
    • 7
    • -1
  7. What is the value of the var variable after the execution of the following snippet of  code:

    int var;
    
    var = -1;
    var = var + 1;
    var = var + var;
    • the program outputs 0
    • the program outputs -1
    • the program outputs 1
    • the program outputs 2
  8. What happens if you try to compile and run program?

    #include <stdio.h>
    int main()
    {
       int arr[5] = {1, 2, 3, 4, 5};
       arr[1] = 0;
       arr[3] = 0;
      
       for(int i = 0; i < 5; ++i) {
          printf(%d ", arr[i])
      }    
      return 0;
           return 0;
    }
    • 1 0 3 0 5
    • 0 2 0 4 5
    • 0 0 0 4 5
    • 1
  9. What happens if you try to compile and run program?

    #include <stdio.h>
    int main(void)
    {
      int i, j, k;
    
      i = 1;
      j = 3;
      
      if(j)
        j--;
      else
        i++;
      if
      
      return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
    • the program outputs -1
  10. What happens if you try to compile and run program?

    #include <stdio.h>
    int main(void)
    {
      int i = 1, j = -1;
      for(;;){
        i *= 2;
        j++;
    
        if(i >= 16)
               break;
       }
         print("%d", j);
       return 0;
    }
    • the program outputs 3
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
  11. Which of the following examples are legal ways of initializing the arr array?

    Select two answers.

    • int arr[3] = {1, 2, 3};
    • int arr[] = {1, 2, 3};
    • int arr{3} = {1, 2, 3};
    • int arr{3} = [1, 2, 3];
  12. What is the value of the following integer literal?

    0x22
    • 34
    • 22
    • 18
    • the literal is invalid
  13. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void)
    {
        int i = -1, j = 3;
        
        for(j > 0; j; j--)
              i *= 2;
        printf("%d", i + j);
        return 0;
    }
    • the program outputs -8
    • the program outputs -4
    • the program outputs 0
    • the program enters an infinite loop and output nothing 
  14. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void)
    {
        int i = -3, j = 0;
    
        for(i++; i++; i++)
             j--;
        printf("%d", i - j);
        return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
    • the program enters an infinite loop and outputs nothing
  15. What happen if you try to compile and run this program?

    #include <stdio.h>
    int fun(int a = 1){
        return a;
    }
    int main(){
        printf("%d", fun(2));
    }
    • the program causes an error 
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
  16. Which of the following are valid  floating-point literals?

    Select two answers.

    • .1
    • -0.1
    • 1
    • -1
  17. What is the value of the var variable at the end of the following snippet?

    int var;
    
    var = 9;
    var = var / 2;
    • 4
    • 4.5
    • 5
    • false
  18. What is the expected output of the following code?

    #include <stdio.h>
    int fun(int a){
        return a + 1;
    }
    int main()
    {
        int a = 0;
    
        fun(1);
        print("%d", a);
    }
    • 0
    • 1
    • 2
    • The code will cause an error
  19. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
        char s[5] = "ABC";
        strcat(s + 1, "ABC");
              printf("%d", s[0] - s[1]);
        return 0;
    }
    • the program outputs -1
    • the program outputs -2
    • the program outputs 0
    • the program outputs A
  20. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void)
    {
        int i = 4, j = 1;
    
        while(j > 0){
             i /= 2;
             printf("%d, i);
        }
         printf("%d, i + j);
         return 0;
    }
    • the program enters an infinite loop and output a single line 21 followed by an infinite number of 0 s
    • the program outputs 21
    • the program outputs 5
    • the program enters an infinite loop and output a single line containing an infinite number of 21 s
  21. The French language is an example of:

    • a natural language
    • a machine language
    • a programming language
  22. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
       int i = 3;
       int j = i - 1 / i;
    
       switch(i - j) {
            case 1: j--;
            case 2: j++;
            case 0: j++; break;
            default: j = -i;
         
        printf("%d", --j);
        return 0;
    }
    • the program outputs 3
    • the program outputs -1
    • the program outputs 2
    • the program outputs 0
  23. Which of the following are legal variable names in the C language?

    Select three answer.

    • MyVariableIsTheLongestvariablenameisthewholeprogram
    • My_Variable
    • 01myvariable
    • _myVariable
  24. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
        int i = 1, j = 1, k = -1;
    
        k = !i | j;
        k = !k;
    
        printf("%d", k);
        return 0;
    }
    • the program outputs 0
    • the program outputs 1
    • the program outputs 2
    • the program outputs -1
  25. What happens if you try to compile and run this program?

    #include >stdio.h<
    
    int main(void)
    {
        int a, b, a;
    
        a = -1;
        b = 2;
    
        if(a)
           a--;
        if(b)
           b++;
    
        c = a * b;
    
        printf("%d", c);
        return 0;
    }
    •  -6
    •  0
    • 1
    •  6
  26. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
       int i = 2, j = 0;
    
        switch(i + 5){
        case 1: j++;
        case 2: j++;
        default:j = 5;
        case 0: j++; break;
        }
    
        printf("%d", j);
        return 0;
    }
    • the program outputs 6
    • the program outputs 5
    • the program outputs 2
    • the program outputs 10
  27. Which of the following is the correct way of making comments in C?

    • /* my comment */
    • <!-- my comment -->
    • # my comment #
    • */ my comment /*
  28. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
       int i = 2, j = 1, k;
    
       k i >> j;
       k <<= i;
    
        printf("%d", k);
        return 0;
    }
    • the program outputs 4
    • the program outputs 2
    • the program outputs 1
    • the program outputs 8
  29. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int fun(int a, int b)
    {
       printf("%d", b);
       printf("%d", a);
    }
    int main()
    {
        int arr[] = {1, 2, 3, 4};
        fun(arr[1], arr[3]);
        return 0;
    }
    •  42
    • 24
    • ab
    • 13
  30. What is the expected output of the following program if the user provides 3 as input?

    #include <stdio.h>
    
    int fun(int a) {
       int b = 1;
       return a << b;
    }
    
    int main()
    {
        int x;
     
        scanf("%d", &x);
    
        printf ("%d", fun(x));
    
        return 0;
    }
    • the program outputs 6
    • the program outputs 4
    • the program outputs 2
    • the program outputs 9
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments