C/C++传递二维数组
C/C++传递二维数组 - [IT资料]
//c语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下:
//方法一, 形参给出第二维的长度。
#include <stdio.h>
void func(int n, char str[][5])
{
int i;
for (i = 0; i < n; i++)
{
printf("\nstr[%d] = %s\n", i, str[i]);
}
}
void main()
{
char str[][5] = {"abc", "def", "ghi"};
func(3, str);
}
//方法二,形参声明为指向数组的指针。
#include <stdio.h>
void func(int n, char (*str)[5])
{
int i;
for (i = 0; i < n; i++)
{
printf("\nstr[%d] = %s\n", i, str[i]);
}
}
void main()
{
char str[][5] = {"abc", "def", "ghi"};
func(3, str);
}
//方法三,形参声明为指针的指针。
#include <stdio.h>
void func(int n, char **str)
{
int i;
for (i = 0; i < n; i++)
{
printf("\nstr
相关文档:
#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#define host "localhost"
#define username "root"
#define password "123"
#define database "oa"
MYSQL *conn;
int main()
{
MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i,ret;
FILE *fp;
MYSQL_FIELD *field;
......
这篇文章是使用SQLite C/C++接口的一个概要介绍和入门指南。
由于早期的SQLite只支持5个C/C++接口,因而非常容易学习和使用,但是随着SQLite功能的增强,新的C/C++接口不断的增加进来,到现在有超过150个不同的API接口。这往往使初学者望而却步。幸运的是,大多数SQLite中的C/C++接口是专用的,因而很少被使用到。尽管有这 ......
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
举个简单例子:用二重循环输出1-100 数字;
当然我这里是举例子针对二重及以上的循环,
完全可以使用单循环,于是便飞快的完成了以下
代码:
如下就用C/C++举例。
C++代码(VS2008):
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(in ......