/*author: clifford*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
/*
print the elements in a 2-dim array.
*/
void print(int **p)
{
printf("%d\n", p[0][0]);
printf("%d\n", p[0][1]);
printf("%d\n", p[1][0]);
printf("%d\n", p[1][1]);
}
int main()
{
int a[2][2] = { {1, 2} , {3, 4} };
printf("%d\n", a[0][0]);
print((int **)a);
printf("%d\n", a[0][1]);
int **p;
p = (int **) malloc(sizeof(int *) * 2);
p[0] = (int *) malloc(sizeof(int) * 2);
p[1] = (int *) malloc(sizeof(int) * 2);
p[0][0] = a[0][0];
p[0][1] = a[0][1];
p[1][0] = a[1][0];
p[1][1] = a[1][1];
printf("The 2nd way.\n");
print(p);
free(p);
/*
The third way, maybe it is the most convenient one now.
*/
p = (int **)malloc(sizeof(int *) * 2);
p[0] = a[0];
p[1] = a[1];
printf("The 3rd way.\n");
print(p);
free(p[0]);
free(p[1]);
free(p);
system("pause");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
最好的C语言教材这配套程序源代码(吐血奉献) (162个子文件)
sample.bmp 153KB
file1.c 3KB
8.7_allocator.c 2KB
2.12_dec_2_hex.c 2KB
6.6_hash_table.c 2KB
6.5_link_list.c 2KB
6.9_use_bit_field.c 2KB
5.11_templete_func_pointer.c 1KB
5.3_pointer_in_mem.c 1KB
5.1_get_address.c 1KB
5.7_multi_dim_def.c 1KB
calculator.c 1KB
7.3_va_arg.c 1KB
8.2_read_and_write.c 1KB
5.7_access_multi_array.c 1KB
5.4_differ_pointer.c 1KB
7.7_line_op.c 1KB
5.2_func_arg.c 1KB
2.4_const_var.c 1KB
5.10_cmd_line_ops.c 1022B
5.9_ptr_with_multi_array.c 1019B
4.11_macro_func.c 1017B
6.3_struct_array.c 996B
8.3_copy.c 994B
5.6_sort_by_pointer.c 986B
7.2_use_printf.c 975B
5.5_differ_pointer_array.c 971B
6.2_struct_in_mem.c 928B
2.11_nested_cond_expr.c 923B
7.4_use_scanf.c 904B
5.11_struct_encapsulation.c 897B
8.4_lseek.c 884B
file2.c 880B
6.1_def_struct.c 874B
3.7_continue_break.c 851B
6.7_typedef.c 825B
2.10_incre_assign_op.c 794B
6.8_use_union.c 755B
5.8_init_ptr_array.c 744B
7.5_file_copy.c 735B
4.9_init_var.c 731B
2.2_size_of_types.c 665B
3.4_switch.c 639B
5.3_array_as_argu.c 568B
4.3_external_var.c 553B
3.6_do_while.c 529B
3.8_goto.c 526B
main.c 513B
4.10_recur.c 479B
5.1_size_of_pointer.c 467B
3.5_while_for.c 465B
2.3_enum.c 379B
7.6_stderr_exit.c 373B
2.3_const_expr.c 359B
3.3_if_else.c 354B
2.3_string_char.c 334B
2.7_type_convert.c 298B
file1.c 294B
2.9_bitwise_and.c 274B
file2.c 263B
7.1_convert.c 256B
main.c 175B
新建 文本文档.c 167B
新建 文本文档.c 166B
file1.c 107B
file2.c 102B
xxv.cpp 21KB
Untitled2.cpp 495B
xx.cpp 329B
dg.cpp 297B
sd.cpp 279B
dff.cpp 273B
xc.cpp 266B
sdf.cpp 224B
sdg.cpp 213B
Untitled1.cpp 201B
s.cpp 195B
sds.cpp 192B
Project1.dev 1KB
Project1.dev 1KB
Project1.dev 964B
Project1.dev 964B
file1.exe 22KB
dff.exe 22KB
5.11_templete_func_pointer.exe 21KB
2.12_dec_2_hex.exe 21KB
5.6_sort_by_pointer.exe 21KB
5.7_multi_dim_def.exe 21KB
3.7_continue_break.exe 21KB
5.7_access_multi_array.exe 21KB
5.1_get_address.exe 21KB
xc.exe 21KB
sdg.exe 21KB
dg.exe 21KB
sdf.exe 21KB
Untitled2.exe 21KB
5.9_ptr_with_multi_array.exe 20KB
5.11_struct_encapsulation.exe 20KB
2.11_nested_cond_expr.exe 20KB
5.4_differ_pointer.exe 20KB
共 162 条
- 1
- 2
资源评论
- 醉卧春秋2012-10-12不错的教材,就是有时打不开
wocao23
- 粉丝: 2
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功