Advanced operations on arrays and pointers, memory management, and the basics of functions M5 Test

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

    #include <stdio.h>
    
    int main(void)
    {
          char *p = "12345", *q = p - 10;
         
          printf("%d",'1[14] - q[13]);
          return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 3
    • the program outputs 4
  2. What happens if you try to compile and run this program?

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

    #include <stdio.h>
    
    int f(int 1)
    {
          ++i;
          return i;
    }
    int main(void)
    {
         int i = 1;
         i = f(i);     
              printf("%d",i);
          return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs an unpredictable value
    • the compilation fails
  4. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
          int i = 0;
          i = f(f(i));
         
          printf("%d",i);
          return 0;
    }
    • the compilation fails
    • the program outputs nul
    • the program outputs NULL
    • the program outputs 0
  5. What happens if you try to compile and run the program?

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

    #include <stdio.h>
    int f(int i) {
        return ++i;
    }
    int main(void)
    {
      int i = 0;
      i = f(f(i));
      printf("%d", i);
      return 0;
    } 
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
    • the compilations fails
  7. What happens if you try to compile and run program?

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

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

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

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

    # include <stdio.h>
    int main(void)
    {
       int *t [10];
       int (*u) [10];
       printf("%d", sizeof(t) != sizeof(u));
       return 0;
    }
    • the program outputs 1
    • the program outputs 0
    • the program outputs 4
    • the program outputs 16
  12. What happens if you try to compile and run program?

    #include <stdio.h>
    int f(int i){
        i++;
    }
    int main(void)
    {
        int i = 1;
        f(i);
       printf("%d", i);
       return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs an unpredictable value
    • the compilation fails
  13. What happens if you try to compile and run program?

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

    #include <stdio.h>
    int f(void){
    }
    int main(void){
       int i;  
       i = f();
       printf("%d", i);
       return 0;
    }
    • the program outputs an unpredictable value
    • the program outputs 0
    • the program outputs NULL
    • the compilation fails
  15. What happens if you try to compile and run program?

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

    #include <stdio.h>
    
    void f(int i){
       i++;
    }
    int main(void)
    {
       int i = 1;
       
       f(i);
       printf("%d", 1);
       return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs  an unpredictable value
    • the compilation fails
  17. What happens if you try to compile and run program?

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

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

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

    #include <stdio.h>
    int main(void)
    {
       int *p = (int *)malloc(2 * sizeof(int));
    
       *p = 2;
       *(p + 1) = *(p) - 1;
       *p = p[1];
       printf("%d", *p);
       free(p);
       return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 3
    • the program outputs 4
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments