Sail E0 Webinar

MCQs

Total Questions : 41 | Page 2 of 5 pages
Question 11.

What is the output of this C code?   int main()    {        int i = 23;        char c = -23;        if (i < c)            printf("Yes\n");        else            printf("No\n");    }

  1.    Yes
  2.    No
  3.    Depends on the compiler
  4.    Depends on the standard
 Discuss Question
Answer: Option B. -> No


None.


Question 12. What is the output of the below code considering size of short int is 2, char is 1 and int is 4 bytes?    int main()    {        short int i = 20;        char c = 97;        printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));        return 0;    }
  1.    2, 1, 2
  2.    2, 1, 1
  3.    2, 1, 4
  4.    2, 2, 8
 Discuss Question
Answer: Option C. -> 2, 1, 4


None.


Question 13. What will be the data type of the result of the following operation? (float)a * (int)b / (long)c * (double)d
  1.    int
  2.    long
  3.    float
  4.    double
 Discuss Question
Answer: Option D. -> double


None.


Question 14. Which type conversion is NOT accepted?
  1.    From char to int
  2.    From float to char pointer
  3.    From negative int to char
  4.    From double to char
 Discuss Question
Answer: Option B. -> From float to char pointer


Conversion of a float to pointer type is not allowed.


Question 15. function tolower(c) defined in library works for?
  1.    Ascii character set
  2.    Unicode character set
  3.    Ascii and utf-8 but not EBSIDIC character set
  4.    Any character set
 Discuss Question
Answer: Option D. -> Any character set


None.


Question 16. Comment on the output of this C code?    int main()    {        int a[5] = {1, 2, 3, 4, 5};        int i;        for (i = 0; i < 5; i++)            if ((char)a[i] == '5')                printf("%d\n", a[i]);            else                printf("FAIL\n");    }
  1.    The compiler will flag an error
  2.    Program will compile and print the output 5
  3.    Program will compile and print the ASCII value of 5
  4.    Program will compile and print FAIL for 5 times
 Discuss Question
Answer: Option D. -> Program will compile and print FAIL for 5 times


The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAILED
FAILED
FAILED
FAILED
FAILED


Question 17. What is the size of an int data type?
  1.    4 Bytes
  2.    8 Bytes
  3.    Depends on the system/compiler
  4.    Cannot be determined
 Discuss Question
Answer: Option C. -> Depends on the system/compiler


The size of the data types depend on the system.


Question 18. The format identifier '%i' is also used for _____ data type?
  1.    char
  2.    int
  3.    float
  4.    double
 Discuss Question
Answer: Option B. -> int


Both %d and %i can be used as a format identifier for int data type.


Question 19. Which of the following is a User-defined data type?
  1.    typedef int Boolean;
  2.    typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
  3.    struct {char name[10], int age};
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


typedef and struct are used to define user-defined data types.


Question 20. Which data type is most suitable for storing a number 65000 in a 32-bit system?
  1.    short
  2.    int
  3.    long
  4.    double
 Discuss Question
Answer: Option A. -> short


65000 comes in the range of short (16-bit) which occupies the least memory.


Latest Videos

Latest Test Papers