C Programming Test And Answer 02

1.What will be the output of the program?

#include<stdio.h>
#include<stdarg.h>
void dumplist(int, ...);

int main()
{
    dumplist(2, 4, 8);
    dumplist(3, 6, 9, 7);
    return 0;
}
void dumplist(int n, ...)
{
    va_list p; int i;
    va_start(p, n);

    while(n-->0)
    {
        i = va_arg(p, int);
        printf("%d", i);
    }
    va_end(p);
    printf("\n");
}

Explanation:
In the list, the first parameter always represents the number of arguments to be passed.

So the 2 in the first function represents that there are 2 arguments.

And 3 in second function represents there are 3 arguments.

So first it prints 4 and 8.

Next, it will print 6, 9, 7. Excluding 4 and 8.
4 and 8 are actually to define a number of parameters. And they are not get printed.

2.Which of the following statements are FALSE about the below code?

int main(int ac, char *av[])
{
}

[A]. ac contains count of arguments supplied at command-line
[B]. av[] contains addresses of arguments supplied at a command line
[C]. In place of ac and av, argc and argv should be used.
[D]. The variables ac and av are always local to main()
Explanation:
Answer C is not correct for this question. According to Posix standard and other standards for declaring variable names, variable name can be any valid variable name. In this case we can use ac and av instead of argc and argv since these are only variable names for argument counter and argument vectors of command line argument.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值