Sail E0 Webinar

MCQs

Total Questions : 41 | Page 3 of 5 pages
Question 21. What is short int in C programming?
  1.    Basic datatype of C
  2.    Qualifier
  3.    short is the qualifier and int is the basic datatype
  4.    All of the mentioned
 Discuss Question
Answer: Option C. -> short is the qualifier and int is the basic datatype


None.


Question 22. What is the output of this C code?    int main()    {       char chr;       chr = 128;       printf("%d\n", chr);       return 0;    }
  1.    128
  2.    -128
  3.    Depends on the compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> -128


signed char will be a negative number.
Output:
$ cc pgm2.c
$ a.out
-128


Question 23. Comment on the output of this C code?    int main()    {        char c;        int i = 0;        FILE *file;        file = fopen("test.txt", "w+");        fprintf(file, "%c", 'a');        fprintf(file, "%c", -1);        fprintf(file, "%c", 'b');        fclose(file);        file = fopen("test.txt", "r");        while ((c = fgetc(file)) !=  -1)            printf("%c", c);        return 0;.    }
  1.    a
  2.    Infinite loop
  3.    Depends on what fgetc returns
  4.    Depends on the compiler
 Discuss Question
Answer: Option A. -> a


None.
Output:
$ cc pgm3.c
$ a.out
a


Question 24. Comment on the output of this C code?    int main()    {        float f1 = 0.1;        if (f1 == 0.1f)            printf("equal\n");        else            printf("not equal\n");    }
  1.    equal
  2.    not equal
  3.    Output depends on compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> equal


0.1f results in 0.1 to be stored in floating point representations.
Output:
$ cc pgm5.c
$ a.out
equal


Question 25. Comment on the output of this C code?    int main()    {        float f1 = 0.1;        if (f1 == 0.1)            printf("equal\n");        else            printf("not equal\n");    }
  1.    equal
  2.    not equal
  3.    Output depends on compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> not equal


0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ a.out
not equal


Question 26. What is the output of this C code (on a 32-bit machine)?    int main()    {        int x = 10000;        double y = 56;        int *p = &x;        double *q = &y;        printf("p and q are %d and %d", sizeof(p), sizeof(q));        return 0;    }
  1.    p and q are 4 and 4
  2.    p and q are 4 and 8
  3.    Compiler error
  4.    p and q are 2 and 8
 Discuss Question
Answer: Option A. -> p and q are 4 and 4


Size of any type of pointer is 4 on a 32-bit machine.
Output:
$ cc pgm6.c
$ a.out
p and q are 4 and 4


Question 27. Which of the datatypes have size that is variable?
  1.    int
  2.    struct
  3.    float
  4.    double
 Discuss Question
Answer: Option B. -> struct


Since the size of the structure depends on its fields, it has a variable size.


Question 28. Which is correct with respect to size of the datatypes?
  1.    char > int > float
  2.    int > char > float
  3.    char < int < double
  4.    double > char > int
 Discuss Question
Answer: Option C. -> char < int < double


char has lesser bytes than int and int has lesser bytes than double in any system


Question 29. What is the output of this C code?    int main()    {        float x = 'a';        printf("%f", x);        return 0;    }
  1.    a
  2.    run time error
  3.    a.0000000
  4.    97.000000
 Discuss Question
Answer: Option D. -> 97.000000


Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
$ cc pgm8.c
$ a.out
97.000000


Question 30. What is the output of the following C code(on a 64 bit machine)?    union Sti    {        int nu;        char m;    };    int main()

    {        union Sti s;        printf("%d", sizeof(s));        return 0;    }

  1.    8
  2.    5
  3.    9
  4.    4
 Discuss Question
Answer: Option D. -> 4


Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.
Output:
$ cc pgm7.c
$ a.out
4


Latest Videos

Latest Test Papers