logo

CuriousTab

CuriousTab

Discussion


Home C Programming Declarations and Initializations See What Others Are Saying!
  • Question
  • Is the following statement a declaration or definition?
    extern int i;


  • Options
  • A. Declaration
  • B. Definition
  • C. Function
  • D. Error

  • Correct Answer
  • Declaration 

    Explanation
    Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i)

    Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference".


    More questions

    • 1. If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?
      #include<stdio.h>
      #include<math.h>
      int main()
      {
          float a=5.375;
          char *p;
          int i;
          p = (char*)&a;
          for(i=0; i<=3; i++)
              printf("%02x\n", (unsigned char)p[i]);
          return 0;
      }
      

    • Options
    • A. 40 AC 00 00
    • B. 04 CA 00 00
    • C. 00 00 AC 40
    • D. 00 00 CA 04
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int i=2;
          printf("%d, %d\n", ++i, ++i);
          return 0;
      }
      

    • Options
    • A. 3, 4
    • B. 4, 3
    • C. 4, 4
    • D. Output may vary from compiler to compiler
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      int main()
      {
          char *i = "55.555";
          int result1 = 10;
          float result2 = 11.111;
          result1 = result1+atoi(i);
          result2 = result2+atof(i);
          printf("%d, %f", result1, result2);
          return 0;
      }
      

    • Options
    • A. 55, 55.555
    • B. 66, 66.666600
    • C. 65, 66.666000
    • D. 55, 55
    • Discuss
    • 4. On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right?

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. What is (void*)0?

    • Options
    • A. Representation of NULL pointer
    • B. Representation of void pointer
    • C. Error
    • D. None of above
    • Discuss
    • 6. Bitwise & and | are unary operators

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. Point out the error in the program.
      #include<stdio.h>
      const char *fun();
      
      int main()
      {
          char *ptr = fun();
          return 0;
      }
      const char *fun()
      {
          return "Hello";
      }
      

    • Options
    • A. Error: Lvalue required
    • B. Error: cannot convert 'const char *' to 'char *'.
    • C. No error and No output
    • D. None of above
    • Discuss
    • 8. In a function that receives variable number of arguments the fixed arguments passed to the function can be at the end of argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 9. Point out the error in the following program.
      #include<stdio.h>
      #include<stdarg.h>
      
      int main()
      {
          void display(char *s, int num1, int num2, ...);
          display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0);
          return 0;
      }
      void display(char *s, int num1, int num2, ...)
      {
          double c;
          char s;
          va_list ptr;
          va_start(ptr, s);
          c = va_arg(ptr, double);
          printf("%f", c);
      }
      

    • Options
    • A. Error: invalid arguments in function display()
    • B. Error: too many parameters
    • C. Error: in va_start(ptr, s);
    • D. No error
    • Discuss
    • 10. Point out the error if any in the following program (Turbo C).
      #include<stdio.h>
      #include<stdarg.h>
      void display(int num, ...);
      
      int main()
      {
          display(4, 'A', 'a', 'b', 'c');
          return 0;
      }
      void display(int num, ...)
      {
          char c; int j;
          va_list ptr;
          va_start(ptr, num);
          for(j=1; j<=num; j++)
          {
              c = va_arg(ptr, char);
              printf("%c", c);
          }
      }
      

    • Options
    • A. Error: unknown variable ptr
    • B. Error: Lvalue required for parameter
    • C. No error and print A a b c
    • D. No error and print 4 A a b c
    • Discuss


    Comments

    There are no comments.

Enter a new Comment