logo

CuriousTab

CuriousTab

Discussion


Home C Programming C Preprocessor See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    #define FUN(i, j) i##j
    
    int main()
    {
        int va1=10;
        int va12=20;
        printf("%d\n", FUN(va1, 2));
        return 0;
    }
    


  • Options
  • A. 10
  • B. 20
  • C. 1020
  • D. 12

  • Correct Answer
  • 20 

    Explanation
    The following program will make you understand about ## (macro concatenation) operator clearly.

    #include<stdio.h>
    #define FUN(i, j) i##j
    
    int main()
    {
        int First  	= 10;
        int Second  = 20;
    
        char FirstSecond[] = "CuriousTab";
    
        printf("%s\n", FUN(First, Second) );
    
        return 0;
    }
    
    Output:
    -------
    CuriousTab
    
    

    The preprocessor will replace FUN(First, Second) as FirstSecond.

    Therefore, the printf("%s\n", FUN(First, Second) ); statement will become as printf("%s\n", FirstSecond );

    Hence it prints CuriousTab as output.

    Like the same, the line printf("%d\n", FUN(va1, 2)); given in the above question will become as printf("%d\n", va12 );.

    Therefore, it prints 20 as output.


    More questions

    • 1. Bitwise & can be used to check if more than one bit in a number is on.

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. It is necessary that a header files should have a .h extension?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. Bitwise | can be used to set multiple bits in number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. Bitwise & can be used to check if a bit in number is set or not.

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. A pointer union CANNOT be created

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      int main()
      {
          union test
          {
              int i;
              float f;
              char c;
          };
          union test *t;
          t = (union test *)malloc(sizeof(union test));
          t->f = 10.10f;
          printf("%f", t->f);
          return 0;
      }
      

    • Options
    • A. 10
    • B. Garbage value
    • C. 10.100000
    • D. Error
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int x=4, y, z;
          y = --x;
          z = x--;
          printf("%d, %d, %d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. 4, 3, 3
    • B. 4, 3, 2
    • C. 3, 3, 2
    • D. 2, 3, 3
    • Discuss
    • 9. Functions cannot return a floating point number

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int a=100, b=200, c;
          c = (a == 100 || b > 200);
          printf("c=%d\n", c);
          return 0;
      }
      

    • Options
    • A. c=100
    • B. c=200
    • C. c=1
    • D. c=300
    • Discuss


    Comments

    There are no comments.

Enter a new Comment