Sail E0 Webinar

MCQs

Total Questions : 7
Question 1. What is the output of this C code?
int main()
{
enum {ORANGE = 12, MANGO, BANANA = 11, APPLE};
printf("APPLE = %d\n", APPLE);
}
  1.    APPLE= 11
  2.    APPLE= 12
  3.    APPLE= 23
  4.    APPLE= 0
 Discuss Question
Answer: Option B. -> APPLE= 12


In enum, the value of constant is defined to the recent assignment from left.


Question 2. What is the output of this C code?
int main()
{
int var = 010;
printf("%d", var);
}
  1.    2
  2.    8
  3.    9
  4.    10
 Discuss Question
Answer: Option B. -> 8


010 is octal representation of 8.


Question 3. What is the output of this C code?
#define a 20
int main()
{
const int a = 50;
printf("a = %d\n", a);
}
  1.    a = 50
  2.    a = 20
  3.    Run time error
  4.    Compilation Error
 Discuss Question
Answer: Option D. -> Compilation Error


The #define substitutes a with 20 leaving no identifier and hence compilation error.
Complilation Error: expected identifier or '(' before numeric constant


Question 4. enum types are processed by?
  1.    Compiler
  2.    Preprocessor
  3.    Linker
  4.    Assembler
 Discuss Question
Answer: Option A. -> Compiler


None.


Question 5. Which is false?
  1.    Constant variables need not be defined as they are declared and can be defined later
  2.    Global constant variables are initialised to zero
  3.    const keyword is used to define constant values
  4.    You cannot reassign a value to a constant variable
 Discuss Question
Answer: Option A. -> Constant variables need not be defined as they are declared and can be defined later


Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Hence the statement a is false.


Question 6. Whats is the output of this C code?
void main()
{
int const k = 11;
k++;
printf("k is %d", k);
}
  1.    k is 12
  2.    Error because const and int are used together
  3.    garbage value
  4.    Error, because a constant variable cannot be changed
 Discuss Question
Answer: Option D. -> Error, because a constant variable cannot be changed


Constant variable has to be declared and defined at the same time. Trying to change it later results in error.


Question 7. What is the output of this C code?
int main()
{
const int a;
a = 32;
printf("a is %d", a);
return 0;
}
  1.    a is 32
  2.    Compile time error
  3.    Run time error
  4.    none
 Discuss Question
Answer: Option B. -> Compile time error


Since the constant variable has to be declared and defined at the same time, not doing it results in an error.


Latest Videos

Latest Test Papers