Sail E0 Webinar

MCQs

Total Questions : 16 | Page 2 of 2 pages
Question 11. Which is valid C expression?
  1.    int my_num = 100,000;
  2.    int my_num = 100000;
  3.    int my num = 1000;
  4.    int $my_num = 10000;
 Discuss Question
Answer: Option B. -> int my_num = 100000;


space, comma and $ cannot be used in a variable name.


Question 12. What is the output of this C code?
int main()
{
printf("Hello World! %d \n", x);
return 0;
}
  1.    Hello World! x;
  2.    Hello World! followed by a junk value
  3.    Compile time error
  4.    Hello World!
 Discuss Question
Answer: Option C. -> Compile time error


It results in an error since x is used without declaring the variable x.
Output:
$ cc pgm1.c
pgm1.c: In function 'main':
pgm1.c:4: error: 'x' undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)


Question 13. What is the output of this C code?
int main()
{
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
return 0;
}
  1.    Compile time error
  2.    Hello World! 34
 Discuss Question
Answer: Option A. -> Compile time error


Since y is already defined, redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function 'main':
pgm2.c:5: error: redefinition of 'y'
pgm2.c:4: note: previous definition of 'y' was here


Question 14. What is the problem in following variable declaration?     
float 3Bedroom-Hall-Kitchen?;
  1.    The variable name begins with an integer
  2.    The special character '-'
  3.    The special character '?'
  4.    All of the mentioned.
 Discuss Question
Answer: Option D. -> All of the mentioned.


A variable name cannot start with an integer, along with that the C compiler
interprets the '-' and '?' as a minus operator and a question mark operator respectively.


Question 15. What will happen if the below program is executed?
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
  1.    It will cause a compile-time error
  2.    It will cause a run-time error
  3.    It will run without any error and prints 3
  4.    It will experience infinite looping
 Discuss Question
Answer: Option C. -> It will run without any error and prints 3


A C program can have same function name and same variable name.
$ cc pgm3.c
$ a.out
3


Question 16. Which of the following is not a valid variable name declaration?
  1.    float PI = 3.14;
  2.    double PI = 3.14;
  3.    int PI = 3.14;
  4.    #define PI 3.14
 Discuss Question
Answer: Option D. -> #define PI 3.14


#define PI 3.14 is a macro preprocessor, it is a textual substitution.


Latest Videos

Latest Test Papers