-
What is the expected output of the following program?
#include <stdio.h>
double x(double x, ...) {
va_list 1;
double s = x, v;
va_start(1,x);
do {
v = va_arg(1,double);
s += v;
} while(v != 0.0);
return s;
}
int main(void) {
printf("%f\n",x(-2., -1., 0., 1., 2., 0.));
return 0;
}
-3.000000
3.000000
-2.000000
2.000000
-
A macro writing a formatted string to the stderr
stream may be implemented as:
#define PREE(...) fprintf(stderr, "__VA_ARGS__")
#define PREE(...) fprintf(stderr, __VA_ARGS__)
#define PREE(...) fprintf(stderr, #__VA_ARGS__)
#define PREE(...) fprintf(stderr, ...)
-
Which of the following function headers is invalid?
void f0(char *s, int n, ...)
void f0(int n, ..., char *s)
void f0(int n, char *s, ...)
void f0(int n, char *s)
-
Only one of the following macro definitions is valid-which one?
#define VARMAC(...) fprintf(x, __VA_ARGS__)
#define VARMAC(...,x) fprintf(x, __VA_ARGS__)
#define VARMAC(x) fprintf(x, __VA_ARGS__)
#define VARMAC(x, ...) fprintf(x, __VA_ARGS__)
-
The stack (understood as an abstract data type) is often referred to as:
-
A header file, needed for a variadic argument list processing, is named:
stdvar.h
vararg.h
varstd.h
stdarg.h
-
What is the expected output of the following program?
#include <stdarg.h>
#include <stdio.h>
int f(int n, ...) {
va_list list;
va_start(list,n);
n = va_arg(list,int);
va_end(list);
return n;
}
int main(void) {
printf("%f\n", f(1, 2, 3, 0));
return 0;
}
-
A list of values stored in a variable of type va_list
may be passed to a function as an argument, but the variable:
- must not be passed as the last argument
- must be properly instantiated before the invocation by means of the
va_start()
function
- must not be only argument
- must not be passed as the first argument
-
What is the expected output of the following code?
#include <stdio.h>
#define VMAC(...) printf("%s\n", #___VA_ARGS__)
int main(void) {
char *s = "macro";
VMAC(s,s,s);
return 0;
}
macro,macro,macro
s,s,s
macromacromacro
sss
-
Which of the following snippets should be put into the code to make it work properly?
#include <stdarg.h>
#include <stdio.h>
int sum(int n, ...) {
va_list list;
double s = 0;
va_start(list,n);
while(n--) {
s += va_arg(list,double);
}
va_end(list);
return s;
}
int main(void) {
double v;
/* put a line here */
printf("%f\n", v);
return 0;
}
v = sum(3, 1., 2., 3.);
v = sum(3, 1., 2.);
v = sum(3, 1.);
v = sum(3, 1L, 2L, 3L);
-
What is the expected output of the following program?
#include <stdio.h>
double x(double x, double y, double z, ...) {
va_list 1;
double s = x, v;
va_start(1,z);
do{
v = va_arg(1,double);
s += v;
}while(v != 0.0);
return s;
}
int main(void) {
printf("%f\n",x(-2., -1., 0., 1., 2., 0.));
return 0;
}
1.000000
0.000000
-2.000000
3.000000
-
The va_arg
, an identifier coming form <stdarg.h>
, is actually a:
- variable
- type
- macro
- function
-
In the stdcall
argument passing convention:
- the stack is cleaned periodically by the OS
- the stack is always clean
- the invokee cleans the stack
- the invoker cleans the stack
-
Copying one instance of va_list
to another is done by the:
strcpy()
function
va_copy()
function
memcpy()
function
memmove()
function
-
The term “cdecl” refers to the name of:
- an obsolete version of the “C” programming language
- a contemporary version of the “C” programming language
- a way of passing arguments to a function
- an obsolete family of compilers
-
The “Pascal” argument passing convention relies on the assumption that:
- arguments are transferred through a stack (the first argument on a list is put at the bottom of the stack)
- arguments are transferred through a shared memory block
- arguments are transferred through the CPU registers
- arguments are transferred through a stack (the first argument on a list is put at the top of the stack)
-
A function with the following header:
int max(int n, va_list vals)
- needs a
va_start (n, vals)
invocation at the boy’s beginning
- needs a
va_start(vals)
invocation at the boy’s begining
- doesn’t need a
va_start()
invocation
- needs a
va_start(vals, n)
invocation at the body’s beginning
-
The vsprintf()
function has the following prototype:
int vsprintf(char *format, va_list ap);
int vsprintf(char *str, char *format, ...);
int vsprintf(char *str, char *format, va_list ap);
int vsprintf(char *str, chat *format);
-
A variable function is a function which:
- accepts more than one invocation at a time
- changes its name during program execution
- changes its address during program execution
- accepts a varying number of arguments
-
The following trigraph is named:
...
- a parabola
- an ellipsis
- a three dot
- a hyperbole