logo

CuriousTab

CuriousTab

Discussion


Home C Programming Variable Number of Arguments See What Others Are Saying!
  • Question
  • Point out the error in the following program.
    #include<stdio.h>
    #include<stdarg.h>
    
    int main()
    {
        void display(int num, ...);
        display(4, 12.5, 13.5, 14.5, 44.3);
        return 0;
    }
    void display(int num, ...)
    {
        float c; int j;
        va_list ptr;
        va_start(ptr, num);
        for(j=1; j<=num; j++)
        {
            c = va_arg(ptr, float);
            printf("%f", c);
        }
    }
    


  • Options
  • A. Error: invalid va_list declaration
  • B. Error: var c data type mismatch
  • C. No error
  • D. No error and Nothing will print

  • Correct Answer
  • Error: var c data type mismatch 

    Explanation
    Use double instead of float in float c;

  • More questions

    • 1. Assuming, integer is 2 byte, What will be the output of the program?
      #include;
      
      int main()
      {
          printf("%x\n", -1>>1);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. 0fff
    • C. 0000
    • D. fff0
    • Discuss
    • 2. What is the output of the program given below?
      #include<stdio.h>
      int main()
      {
          enum status { pass, fail, atkt};
          enum status stud1, stud2, stud3;
          stud1 = pass;
          stud2 = atkt;
          stud3 = fail;
          printf("%d, %d, %d\n", stud1, stud2, stud3);
          return 0;
      }
      

    • Options
    • A. 0, 1, 2
    • B. 1, 2, 3
    • C. 0, 2, 1
    • D. 1, 3, 2
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          char ch;
          ch = 'A';
          printf("The letter is");
          printf("%c", ch >= 'A' && ch <= 'Z'? ch + 'a' - 'A':ch);
          printf("Now the letter is");
          printf("%c\n", ch >= 'A' && ch <= 'Z'? ch : ch + 'a' - 'A');
          return 0;
      }
      

    • Options
    • A. The letter is a
      Now the letter is A
    • B. The letter is A
      Now the letter is a
    • C. Error
    • D. None of above
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int k, num=30;
          k = (num>5? (num <=10? 100 : 200): 500);
          printf("%d\n", num);
          return 0;
      }
      

    • Options
    • A. 200
    • B. 30
    • C. 100
    • D. 500
    • Discuss
    • 5. If a function contains two return statements successively, the compiler will generate warnings. Yes/No?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *str;
          str = "%s";
          printf(str, "K\n");
          return 0;
      }
      

    • Options
    • A. Error
    • B. No output
    • C. K
    • D. %s
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str1[] = "India";
          char str2[] = "CURIOUSTAB";
          char *s1 = str1, *s2=str2;
          while(*s1++ = *s2++)
              printf("%s", str1);
      
          printf("\n");
          return 0;
      }
      

    • Options
    • A. CuriousTab
    • B. BndiaBIdiaCURIOUSTABia
    • C. India
    • D. (null)
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int x=30, *y, *z;
          y=&x; /* Assume address of x is 500 and integer is 4 byte size */
          z=y;
          *y++=*z++;
          x++;
          printf("x=%d, y=%d, z=%d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. x=31, y=502, z=502
    • B. x=31, y=500, z=500
    • C. x=31, y=498, z=498
    • D. x=31, y=504, z=504
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *p;
          p="hello";
          printf("%s\n", *&*&p);
          return 0;
      }
      

    • Options
    • A. llo
    • B. hello
    • C. ello
    • D. h
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i=3, *j, k;
          j = &i;
          printf("%d\n", i**j*i+*j);
          return 0;
      }
      

    • Options
    • A. 30
    • B. 27
    • C. 9
    • D. 3
    • Discuss


    Comments

    There are no comments.

Enter a new Comment