logo

CuriousTab

CuriousTab

Discussion


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


  • Options
  • A. Error: unknown variable ptr
  • B. Error: Lvalue required for parameter
  • C. No error and print A a b c
  • D. No error and print 4 A a b c

  • Correct Answer
  • No error and print A a b c 


  • More questions

    • 1. What will be the output of the program?
      #include<stdio.h>
      int check (int, int);
      
      int main()
      {
          int c;
          c = check(10, 20);
          printf("c=%d\n", c);
          return 0;
      }
      int check(int i, int j)
      {
          int *p, *q;
          p=&i;
          q=&j;
          i>=45? return(*p): return(*q);
      }
      

    • Options
    • A. Print 10
    • B. Print 20
    • C. Print 1
    • D. Compile error
    • Discuss
    • 2. If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?
      #include<stdio.h>
      
      int main()
      {
          FILE *fs, *ft;
          char c[10];
          fs = fopen("source.txt", "r");
          c[0] = getc(fs);
          fseek(fs, 0, SEEK_END);
          fseek(fs, -3L, SEEK_CUR);
          fgets(c, 5, fs);
          puts(c);
          return 0;
      }
      

    • Options
    • A. friend
    • B. frien
    • C. end
    • D. Error in fseek();
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int addmult(int ii, int jj)
      {
          int kk, ll;
          kk = ii + jj;
          ll = ii * jj;
          return (kk, ll);
      }
      
      int main()
      {
          int i=3, j=4, k, l;
          k = addmult(i, j);
          l = addmult(i, j);
          printf("%d %d\n", k, l);
          return 0;
      }

    • Options
    • A. 12 12
    • B. No error, No output
    • C. Error: Compile error
    • D. None of above
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      #define MESS junk
      
      int main()
      {
          printf("MESS\n");
          return 0;
      }
      

    • Options
    • A. junk
    • B. MESS
    • C. Error
    • D. Nothing will print
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          static char *s[] = {"black", "white", "pink", "violet"};
          char **ptr[] = {s+3, s+2, s+1, s}, ***p;
          p = ptr;
          ++p;
          printf("%s", **p+1);
          return 0;
      }
      

    • Options
    • A. ink
    • B. ack
    • C. ite
    • D. let
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int arr[3] = {2, 3, 4};
          char *p;
          p = arr;
          p = (char*)((int*)(p));
          printf("%d, ", *p);
          p = (int*)(p+1);
          printf("%d", *p);
          return 0;
      }
      

    • Options
    • A. 2, 3
    • B. 2, 0
    • C. 2, Garbage value
    • D. 0, 0
    • Discuss
    • 7. Will it result in to an error if a header file is included twice?

    • Options
    • A. Yes
    • B. No
    • C. It is compiler dependent.
    • Discuss
    • 8. While defining a variable argument list function we drop the ellipsis(...)?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. It is not possible to create an array of pointer to structures.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. 
      1 : typedef long a;
      extern int a c;
      2 : typedef long a;
      extern a int c;
      3 : typedef long a;
      extern a c;

    • Options
    • A. 1 correct
    • B. 2 correct
    • C. 3 correct
    • D. 1, 2, 3 are correct
    • Discuss


    Comments

    There are no comments.

Enter a new Comment