Flow control (loops), int and float types, type casting, and computer logic M3 Test

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

    #include <stdio.h>
    
    int main(void)
    {
       float x, y;
       int i, j;
    
       x = 1.5; y = 2.0;
       i = x * y + (float)i / j;
    
       printf("%f", x);
       return 0;
    }
    • the program outputs3.500000
    • the program outputs2.000000
    • the program outputs3.000000
    • the program outputs4.000000
  2. What happens if you try to compile and run this program?

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

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

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

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

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

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

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

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

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

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

    #include <stdio.h>
    
    int main(void)
    {
       float x, y;
       int i, j;
    
       x = 1.5; y = 2.0;
       i = 2, j = 3;
       x = x * y + i / j;
    
       printf("%f", x);
       return 0;
    }
    • the program outputs3.000000
    • the program outputs1.000000
    • the program outputs0.000000
    • the program outputs2.000000
  13. What is the value of the  var variable at the end of the following snippet?

    #include <stdio.h>
    
    int main(void)
    {
       int i;
           i = 1;
       while(i < 16)
           i *= 2;   
    
       printf("%d", i);
       return 0;
    }
    • 16
    • 32
    • 0
    • 4
  14. What happens if you try to compile and run this program?

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

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

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

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

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

    #include <stdio.h>
    
    int main(void)
    {
          int i = 0, j = 1, k;
    
              k i << j + j << i;
         
          printf("%d",k);
          return 0;
    }
    • the program outputs 0
    • the program outputs 3
    • the program outputs 2
    • the program outputs 1
  20. What happens if you try to compile and run this 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 5
    • the program outputs 6
    • the program outputs 7
    • the program outputs 4
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments