logo

CuriousTab

CuriousTab

Discussion


Home C Programming Functions See What Others Are Saying!
  • 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


    More questions

    • 1. It is necessary to call the macro va_end if va_start is called in the function.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Left shifting a number by 1 is always equivalent to multiplying it by 2.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%%%%\n");
          return 0;
      }
      

    • Options
    • A. %%%%%
    • B. %%
    • C. No output
    • D. Error
    • Discuss
    • 4. A function that receives variable number of arguments should use va_arg() to extract arguments from the variable argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          float a = 0.7;
          if(0.7 > a)
              printf("Hi\n");
          else
              printf("Hello\n");
          return 0;
      }
      

    • Options
    • A. Hi
    • B. Hello
    • C. Hi Hello
    • D. None of above
    • Discuss
    • 6. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample friday tuesday sunday
      /* sample.c */
      #include<stdio.h>
      
      int main(int sizeofargv, char *argv[])
      {
          while(sizeofargv)
              printf("%s", argv[--sizeofargv]);
          return 0;
      }
      

    • Options
    • A. sample friday tuesday sunday
    • B. sample friday tuesday
    • C. sunday tuesday friday sample
    • D. sunday tuesday friday
    • Discuss
    • 7. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample friday tuesday sunday
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          printf("%c", *++argv[2] );
          return 0;
      }
      

    • Options
    • A. s
    • B. f
    • C. u
    • D. r
    • Discuss
    • 8. Point out the error in the program.
      #include<stdio.h>
      
      int main()
      {
          const int k=7;
          int *const q=&k;
          printf("%d", *q);
          return 0;
      }
      

    • Options
    • A. Error: RValue required
    • B. Error: Lvalue required
    • C. Error: cannot convert from 'const int *' to 'int *const'
    • D. No error
    • Discuss
    • 9. Bit fields CANNOT be used in union.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. What will be the output of the program (myprog.c) given below if it is executed from the command line?
      cmd> myprog 10 20 30
      /* myprog.c */
      #include<stdio.h>
      
      int main(int argc, char **argv)
      {
          int i;
          for(i=0; i<argc; i++)
              printf("%s\n", argv[i]);
          return 0;
      }
      

    • Options
    • A. 10 20 30
    • B. myprog 10 20
    • C. myprog 10 20 30
    • D. 10 20
    • Discuss


    Comments

    There are no comments.

Enter a new Comment