Last Updated on October 18, 2019 by InfraExam

CLA – Programming Essentials in C Quizzes Mock Test Exam Answers Full 100%

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

    017
    • 17
    • 15
    • 23
    • the literal is invalid
  2. What is the value of the following integer literal?

    0x17
    • 15
    • 17
    • the literal is invalid
    • 23
  3. Which of the following strings is a valid variable name?

    • none of these
    • anti_world
    • anti:world
    • anti-world
  4. Which of the following declarations is valid?

    • float float;
    • float int;
    • float long;
    • float floating;
  5. What is the value of the X variable at the end of the following snippet?

        int X = 8;
        X = X - X / 2;
        X = X * X / 4;
        X = X + 2 * X;
    • 14
    • 16
    • 12
    • 10
  6. What is the value of the X variable at the end of the following snippet?

        float X = 2.0;
        X = X + X * 4;
        X = X / X * X;
        X = X / X + X;
    • 11.000000
    • 0.500000
    • 1.000000
    • 110.000000
  7. Which of the following strings is a proper floating-point number (in the “C” language sense)?

     

    • 3E8
    • 3,0×10^8
    • 300,000,000
    • 3.0×10^8
  8. What is the value of the Y variable at the end of the following snippet?

        int X = 1, Y = X + 2, Z = Y++;
    
        Z = X / Y * --X * Y--;
    • 5
    • 3
    • 1
    • 7
  9. What is the value of the X variable at the end of the following snippet?
        int X;
    
        X = ('r' - 's') * ('A' / 'Z');

     

    • 1
    • the snippet is invalid and will cause a compilation error
    • 2
    • 0
  10. What happens if you try to compile and run this program?

        #include <stdio.h>
        int main(void) {
            int x = 1, y = 1;
            float k = -1e0, m = 2e1;
            printf("%d\n", (x >= y) + (x >= y) + (k >= y) + (m >= k) + ('q' <= 'z'));
            return 0;
        }

     

    • the program outputs 4
    • the program outputs 1
    • the program outputs 3
    • the program outputs 2
  11. What happens if you try to compile and run this program?

        #include <stdio.h>
        int main(void) {
            int i = 1;
            if(i = 0)
            	i = 2;
            else
            	i = 3;
            printf("%d\n",i);
            return 0;
        }

     

    • the program outputs 4
    • the program outputs 2
    • the program outputs 1
    • the program outputs 3
  12. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = 1, j = 0;
            do {
            	i *= 2;
            	j += i / 2;
            } while(j < 1);
            printf("%d",i + j); 
            return 0; 
        }

     

    • the program outputs 3
    • the program outputs 1
    • the program enters an infinite loop and does not output anything
    • the program outputs 2
  13. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = 5, j = 16;
            while(j >= 0) {
            	i /= 2;
            	j -= i / 2;
            } 
            printf("%d",i + j); 
            return 0; 
        }

     

    • the program enters an infinite loop and does not output anything
    • the program outputs 1
    • the program outputs 3
    • the program outputs 2
  14. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = 1, j;
            for(j = 0; j ; j--) 
            	i *= 2;
            printf("%d",i + j); 
            return 0; 
        }

     

    • the program outputs 1
    • the program enters an infinite loop and does not output anything
    • the program outputs 2
    • the program outputs 3
  15. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = -1, j = 1;
            for(i++; i++; i++) 
            	j++;
            printf("%d",i + j); 
            return 0; 
        }

     

    • the program outputs 3
    • the program enters an infinite loop and does not output anything
    • the program outputs 1
    • the program outputs 2
  16. 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) + (j >> i) + (i >> i) + (j >> j);
            k <<= i;
            printf("%d", k); 
            return 0; 
        }

     

    • the program outputs 0
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
  17. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = 3, j = i - 2 * i;
            switch(i - j) {
            	case  1: j++;
            	case  2: j--;
            	case  0: j++; break;
            	default: j = 0;
            }
            printf("%d", ++j); 
            return 0; 
        }

     

    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
    • the program outputs 0
  18. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            int i = 5, j = i - 4 * i;
            switch(j) {
            	default: j = 2;
            	case  1: j--; break;
            	case  2: j++;
            	case  0: j--; break;
            }
            printf("%d", j++); 
            return 0; 
        }

     

    • the program outputs 4
    • the program outputs 0
    • the program outputs 2
    • the program outputs 1
  19. What happens if you try to compile and run this program?

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

        #include <stdio.h> 
        int main(void) { 
            int i, s = 0, t[] = {16, 8, 4, 2, 1, 0};
            for(i = 5; t[i] > 2; i /= 2) 
            	s += t[i];
            printf("%d\n", s);
            return 0; 
        }

     

    • the program outputs 0
    • the program outputs 4
    • the program outputs 2
    • the program outputs 1
  21. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            char t[] = { 'x', 'z', 'Y', 'Z', '2' , '0'};
            printf("%d\n", t[t[1] - t[0] - t[3] + t[2] + 3] - t[5]);
            return 0; 
        }

     

    • the program outputs 0
    • the program outputs 2
    • the program outputs 4
    • the program outputs 1
  22. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            float a = 3.14E0, *b = &a, **c = &b;
            **c = a + (a == *b);
            printf("%f", a);
            return 0; 
        }

     

    • the program outputs 4.140000
    • the program outputs NULL
    • the program outputs 2.140000
    • the program outputs 3.140000
  23. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            char t[4][4];
            printf("%d\n",sizeof(t) / sizeof(t[0]) / sizeof(t[0][0]));
            return 0; 
        }

     

    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  24. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            char *p = "\0\2\1\3\4";
            printf("%d\n", p[p[2]] + *(p + 1) + p[0]);
            return 0; 
        }

     

    • the program outputs 8
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
  25. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <string.h>
        int main(void) { 
            char tt[20] = "9081726354";
            strcpy(tt, tt + 3);
            printf("%d\n", strlen(tt) - tt[9] + '5');
            return 0; 
        }

     

    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  26. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <string.h>
        int main(void) { 
            char tt[20] = "0123456789";
            strcat(tt + 11, "123");
            printf("%d\n", strlen(tt) - tt[8] + '0');
            return 0; 
        }

     

    • the program outputs 2
    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
  27. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <stdlib.h>
        int main(void) { 
            float *t = 1 + (float *) malloc(sizeof(float) * sizeof(float));
            t--;
            *t = 8.0;
            t[1] = *t / 4.0;
            t++;
            t[-1] = *t / 2.0;
            printf("%f\n",*t);
            free(--t);
            return 0; 
        }

     

    • the program outputs 1.000000
    • the program outputs 8.000000
    • the program outputs 4.000000
    • the program outputs 2.000000
  28. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <string.h>
        struct S {
            char S[8];
        };
        int main(void) { 
            struct S S = { 'a', 'b', 'c', 'd' };
            printf("%d", sizeof(S.S) - strlen(S.S) + S.S[4]); 
            return 0; 
        }

     

    • the program outputs 4
    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
  29. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <string.h>
        #include <stdlib.h>
        struct S {
            char *S;
        };
    
        int main(void) { 
            struct S *S = (struct S *) malloc(sizeof(struct S));
            S -> S = "123\0""45678";
            printf("%d", strlen(S -> S + 5) + S -> S[3]); 
            free(S);
            return 0; 
        }

     

    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
    • the program outputs 1
  30. What happens if you try to compile and run this program?

        #include <stdio.h> 
        struct S {
            int Var;
            struct S *Str;
        };
        int main(void) { 
            struct S S[] = { { 8, NULL }, { 4, &S[0] }, { 2, &S[1] } };
            printf("%d", S[2].Str->Str->Var);
            return 0; 
        }

     

    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
    • the program outputs 8
  31. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int fun(int *t) {
            return *(t + 3);
        }
        int main(void) { 
            int arr[] = { 3, 2, 1, 0 };
            printf("%d\n", fun(arr - 2));
            return 0; 
        }

     

    • the program outputs 1
    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
  32. What happens if you try to compile and run this program?

        #include <stdio.h> 
        float f(float v) { 
            	v = v / 2.0;
            return v + v;
        } 
        int main(void) { 
            float x = 4; 
            f(x); 
            printf("%f",x); 
            return 0; 
        }

     

    • the program outputs 8.000000
    • the program outputs 1.000000
    • the program outputs 4.000000
    • the program outputs 2.000000
  33. What happens if you try to compile and run this program?

        #include <stdio.h> 
        char *f(char *p) { 
            return p += 2;
        } 
        char *g(char *p) {
            return --p;
        }
        int main(void) { 
            char *s = "ABCDEFGHIJ";
            char  p = *f(g(f(s + 1)));
            printf("%d",p - 'A'); 
            return 0; 
        }

     

    • the program outputs 1
    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
  34. What happens if you try to compile and run this program?

        #include <stdio.h> 
        struct S {
            int S[3];
        };
        void f(struct S S) { 
            S.S[0] = S.S[1] + S.S[2] - 4;
        } 
        int main(void) { 
            struct S S = { { 1, 4, 2 } };
            f(S);
            printf("%d",S.S[1] * S.S[0]); 
            return 0; 
        }

     

    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  35. What happens if you try to compile and run this program?

        #include <stdio.h> 
        struct S {
            int S[3];
        };
        void f(struct S *S) { 
            S->S[2] = 6 * S->S[0] + S -> S[1];
        } 
        int main(void) { 
            struct S S = { { 1, 2 } }, *P = &S;
            f(P);
            printf("%d",S.S[2] / S.S[0]); 
            return 0; 
        }

     

    • the program outputs 2
    • the program outputs 1
    • the program outputs 4
    • the program outputs 8
  36. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #include <string.h>
        char *f(int p, char *s) { 
            s[p + 2] = '\0';
            return s - 1;
        } 
        int main(void) { 
            char s[] = "ABCDEF";
            int i = strlen(f(1,s + 2));
            printf("%d\n",i); 
            return 0; 
        }

     

    • the program outputs 4
    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
  37. What happens if you try to compile and run this program?

        #include <stdio.h> 
        int main(void) { 
            char s[20] = "?"; 
            FILE *f = fopen("fopen","w"); 
            int i = fputs("789",f); 
            fclose(f); 
            f = fopen("fopen","r"); 
            fgets(s + 1,3,f); 
            printf("%c\n", s[2] - s[3]); 
            fclose(f); 
            return 0; 
        }

     

    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
    • the program outputs 2
  38. What happens if you try to compile and run this program?

        #include <stdio.h> 
        #define  ONE    1
        #define  TWO 	ONE + ONE
        int main(void) { 
            int i = 2;
            i = i - 2 * TWO;
            printf("%d\n", i);
            return 0; 
        }

     

    • the program outputs 4
    • the program outputs 2
    • the program outputs 1
    • the program outputs 0
  39. What is the meaning of the following declaration?

        float *f(int);
    • f is a pointer to function (int) returning float;
    • f is a function (int) returning pointer to float;
    • f is a pointer to function (float) returning int;
    • the declaration is incorrect
  40. Select the proper form for the following declaration:
    ptr is a pointer to pointer to pointer to double

    • double **ptr;
    • double ***ptr;
    • double *ptr;
    • the declaration is invalid and cannot be coded in C