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*
}
#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++模板用法:定义、使用 示例
- C++问题string的一些用法示例
- PHP全功能无变形图片裁剪操作类与用法示例
- [C++] vector 之 accumulate 用法示例
- C++ 之 CreateThread 与beginThreadex用法具体示例解析 多线程 (三)
- [C++] vector 之 accumulate 用法示例
- c/c++中define用法详解及代码示例
- c/c++中define用法详解及代码示例
- 范型示例--------摘自MSDN
- c/c++中define用法详解及代码示例
- C++用法的学习心得(要求包含示例,并反映出利用网络获取帮助的过程)
- C++自带sort函数的用法及示例
- MSDN关于C++中heap corrupt的代码示例
- C++用法的学习心得(要求包含示例,并反映出利用网络获取帮助的过程)
- 示例解析 C++ 的 new / delete 和 new [] / delete [] 之用法
- C++名字空间的主要用法示例
- c/c++中define用法详解及代码示例
- c/c++中define用法详解及代码示例
- C++中sort的用法示例
- C++ 中引用(&)的用法和应用实例 (转载)