Saturday, 11 October 2014

C Aptitude Questions and Answers


Predict the output or error(s) for the following:

1.     void main()

{


}

Answer:

Compiler error: Cannot modify a constant value. Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".



2. What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         for (k < 3; k++)
  6.         printf("Hello");
  7.     }
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Answer:a
3. What is the output of this C code?
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++)
  6.             printf("Hello");
  7.     }
a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
Answer:b


No comments:

Post a Comment