logo

CuriousTab

CuriousTab

Discussion


Home C Programming Functions See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    int i;
    int fun1(int);
    int fun2(int);
    
    int main()
    {
        extern int j;
        int i=3;
        fun1(i);
        printf("%d,", i);
        fun2(i);
        printf("%d", i);
        return 0;
    }
    int fun1(int j)
    {
        printf("%d,", ++j);
        return 0;
    }
    int fun2(int i)
    {
        printf("%d,", ++i);
        return 0;
    }
    int j=1;
    


  • Options
  • A. 3, 4, 4, 3
  • B. 4, 3, 4, 3
  • C. 3, 3, 4, 4
  • D. 3, 4, 3, 4

  • Correct Answer
  • 4, 3, 4, 3 

    Explanation
    Step 1: int i; The variable i is declared as an global and integer type.

    Step 2: int fun1(int); This prototype tells the compiler that the fun1() accepts the one integer parameter and returns the integer value.

    Step 3: int fun2(int); This prototype tells the compiler that the fun2() accepts the one integer parameter and returns the integer value.

    Step 4: extern int j; Inside the main function, the extern variable j is declared and defined in another source file.

    Step 5: int i=3; The local variable i is defines as an integer type and initialized to 3.

    Step 6: fun1(i); The fun1(i) increements the given value of variable i prints it. Here fun1(i) becomes fun1(3) hence it prints '4' then the control is given back to the main function.

    Step 7: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

    Step 8: fun2(i); The fun2(i) increements the given value of variable i prints it. Here fun2(i) becomes fun2(3) hence it prints '4' then the control is given back to the main function.

    Step 9: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

    Hence the output is "4 3 4 3".


    More questions

    • 1. Bitwise can be used to reverse a sign of a number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. Bitwise can be used to generate a random number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. A function that receives variable number of arguments should use va_arg() to extract the last argument from the variable argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. Bitwise & can be used to check if more than one bit in a number is on.

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

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

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

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

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

    • Options
    • A. Yes
    • B. No
    • Discuss


    Comments

    There are no comments.

Enter a new Comment