• ( 1 ) What will be the output of the program?
      #include
      #define int char
      void main()
      {
      int i = 65;
      printf("sizeof(i)=%d", sizeof(i));

    • 1) sizeof(i)=2
    • 2) sizeof(i)=1
    • 3) Compiler Error
    • 4) None of these
    • Discussion in forum
      Answer : 2) sizeof(i)=1
      Solution :








      discussion


      Answer : 2) sizeof(i)=1

    • ( 2 ) Which of the following are C preprocessors?

    • 1) #ifdef
    • 2) #define
    • 3) #endif
    • 4) All of the above
    • Discussion in forum
      Answer : 4) All of the above
      Solution :








      discussion


      Answer : 4) All of the above

    • ( 3 ) What will be the output of the following program?
      #include
      #define square(x) x*x
      void main()
      {
      int i;
      i = 64/square(4);
      printf("%d", i);
      }

    • 1) 4
    • 2) 64
    • 3) 16
    • 4) None of these
    • Discussion in forum
      Answer : 2) 64
      Solution :








      discussion


      Answer : 2) 64

    • ( 4 ) In which stage the following code
      #include
      gets replaced by the contents of the file stdio.h

    • 1) During Preprocessing
    • 2) During Execution
    • 3) During linking
    • 4) During Editing
    • Discussion in forum
      Answer : 1) During Preprocessing
      Solution :








      discussion


      Answer : 1) During Preprocessing

    • ( 5 ) What will be the output of the program?
      #include
      #define SQR(x)(x*x)
      int main()
      {
      int a, b= 3;
      a = SQR(b+2);
      printf("%d\n", a);
      return 0;
      }

    • 1) 25
    • 2) 11
    • 3) Error
    • 4) Garbage value
    • Discussion in forum
      Answer : 2) 11
      Solution : The macro function
      SQR(x)(x*x)
      calculate the square of the given number 'x'. (Eg: 102)
      Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3.
      Step 2: a = SQR(b+2);becomes,
      => a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x.
      => a = 3+2 * 3+2;
      => a = 3 + 6 + 2;
      => a = 11;
      Step 3: printf("%d\n", a); It prints the value of variable 'a'.
      Hence the output of the program is 11








      discussion


      Answer : 2) 11

    • ( 6 ) Point out the error in the program
      #include
      int main()
      {
      int i;
      #if A
      printf("Enter any number:");
      scanf("%d", &i);
      #elif B
      printf("The number is odd");
      return 0;
      }

    • 1) Error: unexpected end of file because there is no matching #endif
    • 2) The number is odd
    • 3) Garbage values
    • 4) None of these
    • Discussion in forum
      Answer : 1) Error: unexpected end of file because there is no matching #endif
      Solution : The conditional macro #if must have an #endif. In this program there is no #endif statement written.








      discussion


      Answer : 1) Error: unexpected end of file because there is no matching #endif

    • ( 7 ) #include
      #define X 3
      #if !X
      printf("India");
      #else
      printf("Quiz");
      #endif
      int main()
      {
      return 0;
      }

    • 1) India
    • 2) Quiz
    • 3) Compiler Error
    • 4) Runtime Error
    • Discussion in forum
      Answer : 3) Compiler Error
      Solution : A program is converted to executable using following steps 1) Preprocessing 2) C code to object code conversion 3) Linking The first step processes macros. So the code is converted to following after the preprocessing step.
      printf("Quiz");
      int main()
      {
      return 0;
      }
      The above code produces error because printf() is called outside main. The following program works fine and prints "Quiz"
      #include
      #define X 3
      int main()
      {
      #if !X
      printf("India");
      #else
      printf("Quiz");
      #endif
      return 0;
      }








      discussion


      Answer : 3) Compiler Error

    • ( 8 ) What will be the output of the program?
      #include
      #define CUBE(x) (x*x*x)
      int main()
      {
      int a, b= 3;
      a = CUBE(b++);
      printf("%d, %d\n", a, b);
      return 0;
      }

    • 1) 9, 4
    • 2) 27, 4
    • 3) 27, 6
    • 4) Error
    • Discussion in forum
      Answer : 3) 27, 6
      Solution : The macro function CUBE(x) (x*x*x) calculates the cubic value of given number(Eg: 103.)
      Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.
      Step 2: a = CUBE(b++); becomes
      => a = b++ * b++ * b++;
      => a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.
      => a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)
      Step 3: printf("%d, %d\n", a, b); It prints the value of variable a and b.
      Hence the output of the program is 27, 6








      discussion


      Answer : 3) 27, 6

    • ( 9 ) Which file is generated after pre-processing of a C program?

    • 1) .p
    • 2) .i
    • 3) .o
    • 4) .m
    • Discussion in forum
      Answer : 2) .i
      Solution : After the pre-processing of a C program, a .i file is generated which is passed to the compiler for compilation.








      discussion


      Answer : 2) .i

    • ( 10 ) What will be the output of the C program ?
      #include
      #include
      #define MACRO(num) ++num
      int main()
      {
      char *ptr = "preprocessor";
      int num =strlen(ptr);
      printf("%s ", MACRO(ptr));
      printf("%d", MACRO(num));
      return 0;
      }

    • 1) preprocessor 12
    • 2) preprocessor 13
    • 3) reprocessor 13
    • 4) reprocessor 12
    • Discussion in forum
      Answer : 3) reprocessor 13
      Solution : int num = strlen(ptr);
      int num = 12;
      printf("%s", MACRO(preprocessor));
      printf("%s", reprocessor);
      printf("%d", MACRO(num));
      printf("%d", 13);
      Thus output is reprocessor 13








      discussion


      Answer : 3) reprocessor 13





Top