您的位置:首页 > 编程语言 > C语言/C++

C++ 可变形参 用法示例[摘自MSDN]

2010-08-02 19:36 513 查看
#include <stdio.h>
#include <stdarg.h>

void testit ( int i, ...)
{
va_list argptr;
va_start(argptr, i);

if ( i == 0 ) {
int n = va_arg( argptr, int );
printf( "%d/n", n );
} else {
char *s = va_arg( argptr, char* );
printf( "%s/n", s);
}
}

int main()
{
testit( 0, 0xFFFFFFFF ); // 1st problem: 0xffffffff is not an int
testit( 1, NULL ); // 2nd problem: NULL is not a char*
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ include null list