logo

CuriousTab

CuriousTab

Discussion


Home C Programming Functions Comments

  • Question
  • If a function contains two return statements successively, the compiler will generate warnings. Yes/No?


  • Options
  • A. Yes
  • B. No

  • Correct Answer
  • Yes 

    Explanation
    Yes. If a function contains two return statements successively, the compiler will generate "Unreachable code" warnings.

    Example:

    
    #include<stdio.h>
    int mul(int, int); /* Function prototype */
    
    int main()
    {
        int a = 4, b = 3, c;
        c = mul(a, b);
        printf("c = %d\n", c);
        return 0;
    }
    int mul(int a, int b)
    {
       return (a * b);
       return (a - b); /* Warning: Unreachable code */
    }
    

    Output:
    c = 12


    Functions problems


    Search Results


    • 1. Names of functions in two different files linked together must be unique

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. Functions can be called either by value or reference

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. A function may have any number of return statements each returning different values.

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. If return type for a function is not specified, it defaults to int

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. A function cannot be defined inside another function

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. Functions cannot return a floating point number

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 7. Maximum number of arguments that a function can take is 12

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. Every function must return a value

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. Will the following functions work?
      int f1(int a, int b)
      {
          return ( f2(20) );
      }
      int f2(int a)
      {
          return (a*a);
      }
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 10. In a function two return statements should never occur.

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


    Comments

    There are no comments.

Enter a new Comment