Sail E0 Webinar

MCQs

Total Questions : 15 | Page 1 of 2 pages
Question 1. 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 2. 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 3. 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 4. 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 5. 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


Question 6. 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 7. 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.


Question 8. 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 9. 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 10. 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.


Latest Videos

Latest Test Papers