C Programming – Variable Length Argument

C Programming - Variable Length Argument

Question 1
What is the output of this C code?
    #include 
    #include 
    void func(int, ...);
    int main()
    {
    func(2, 3, 5, 7, 11, 13);
    return 0;
    }
    void func(int n, ...)
    {
    int number, i = 0;
    va_list start;
    va_start(start, n);
    while (i != 3)
    {
    number = va_arg(start, int);
    i++;
    }
    printf("%d", number);
    }
A
3
B
5
C
7
D
11
Question 2
Which of the following function with ellipsis are illegal?
A
void func(…);
B
void func(int, …);
C
void func(int, int, …);
D
Both (a) and (c)
Question 3
 Which of the following data-types are promoted when used as a parameter for an ellipsis?
A
char
B
short
C
int
D
None of the mentioned
Question 4
Which header file includes a function for variable number of arguments?
A
stdlib.h
B
stdarg.h
C
ctype.h
D
Both (a) and (b)
Question 5
Which of the following macro extracts an argument from the variable argument list (ie ellipsis)      and advance the pointer to the next argument?
A
va_list
B
va_arg
C
va_end
D
va_start
Question 6
 The type va_list is used in an argument list
A
To declare a variable that will refer to each argument in turn;
B
For cleanup
C
To create a list
D
There is no such type
Question 7
The declaration … can
A
Appear anywhere in the function declaration
B
Only appear at the end of an argument list.
C
Nothing
D
Both a & b
Question 8
 Each call of va_arg
A
returns one argument
B
Steps va_list variable to the next
C
Both a & b
D
None of the mentioned
Question 9
The standard header _______ is used for variable list arguments (…) in C.
A
B
C
D
Question 10
va_end does whatever.
A
Cleanup is necessary
B
Bust be called before the program returns.
C
Both a &
D
None of the mentioned
Question 11
What is the output of this C code?
    #include 
    int f(char chr, ...);
    int main()
    {
    char c = 97;
    f(c);
    return 0;
    }
    int f(char c, ...)
    {
    printf("%c\n", c);
    }
A
Compile time error
B
Undefined behaviour
C
97
D
a
Question 12
What is the output of this C code?
    #include 
    #include 
    int f(...);
    int main()
    {
    char c = 97;
    f(c);
    return 0;
    }
    int f(...)
    {
    va_list li;
    char c = va_arg(li, char);
    printf("%c\n", c);
    }
A
Compile time error
B
Undefined behaviour
C
97
D
a
Question 13
What is the output of this C code?
    #include 
    #include 
    int f(char c, ...);
    int main()
    {
    char c = 97, d = 98;
    f(c, d);
    return 0;
    }
    int f(char c, ...)
    {
    va_list li;
    va_start(li, c);
    char d = va_arg(li, char);
    printf("%c\n", d);
    va_end(li);
    }
A
Compile time error
B
Undefined behaviour
C
a
D
b
Question 14
What is the output of this C code?
    #include 
    #include 
    int f(char c, ...);
    int main()
    {
    char c = 97, d = 98;
    f(c, d);
    return 0;
    }
    int f(char c, ...)
    {
    va_list li;
    va_start(li, c);
    char d = va_arg(li, int);
    printf("%c\n", d);
    va_end(li);
    }
A
Compile time error
B
Undefined behaviour
C
a
D
b
Question 15
What is the output of this C code?
    #include 
    #include 
    int f(int c, ...);
    int main()
    {
    int c = 97;
    float d = 98;
    f(c, d);
    return 0;
    }
    int f(int c, ...)
    {
    va_list li;
    va_start(li, c);
    float d = va_arg(li, float);
    printf("%f\n", d);
    va_end(li);
    }
A
Compile time error
B
Undefined behaviour
C
97.000000
D
98.000000


Check Your Answers:

  1. C
  2. A
  3. A
  4. B
  5. B
  6. A
  7. B
  8. D
  9. D
10. C
11. A
12. A
13. B
14. D
15. B

 
SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment