C point and array practice
来源:互联网 发布:php前端和后端 编辑:程序博客网 时间:2024/06/11 08:27
#include "stdio.h" #include "stdlib.h"#define SIZE 2#include "string.h"void myprint(int *p) { printf("array[1]= %d\n",*p); p++; printf("array[1]= %d\n",*p);}main () {//using multi array//multi array will allocate memory directly in stack printf("****************************\n"); char president[SIZE][10] = {0}; char (*p)[10]; p = president; strcpy((char *)p,"aa"); p++; strcpy((char *)p,"bb"); int x,index; for(x=0;x<SIZE;x++) { index = 0; while(president[x][index] != '\0') { putchar(president[x][index]); index++; } putchar('\n'); }//-----using array which contain pointer, you still need malloc memory for the pointer's content printf("****************************\n"); char *pointarray[10]; char *q; q=(char* )malloc(20); strcpy(q,"aaaaaa"); pointarray[1] = q; printf("pointarray[1]= %s\n",pointarray[1]); printf("size of char * %lud\n", sizeof(char *)); printf("size of point %lud\n", sizeof(int *));//-------using double ** pointer, you need first malloc memeory for pointer self!!---//allocate two pointer's space, each pointer's content is still pointer printf("****************************\n"); char **doublestar= (char **)malloc(2*sizeof(char *)); char **tmp = doublestar; char *tmpp; char *tmpq; tmpp=(char* )malloc(20); tmpq=(char* )malloc(20); strcpy(tmpp,"abcbbb"); strcpy(tmpq,"abcaaa"); *tmp= tmpp; tmp++; *tmp= tmpq; printf("*doublestar is %s\n",*doublestar); doublestar++; printf("*doublestar is %s\n",*doublestar);//---------using array name as function parameter printf("****************************\n"); int intarray[2]; intarray[0] = 2; intarray[1] = 4; myprint(intarray); return(0);} Result:gcc -g -c aa.c gcc -g -o aa aa.o ./aa ****************************aabb****************************pointarray[1]= aaaaaasize of char * 8dsize of point 8d*****************************doublestar is abcbbb*doublestar is abcaaa****************************array[1]= 2array[1]= 4
#include "stdio.h" #include "stdlib.h"#define SIZE 2#include "string.h"main () { int i = 5; int *p =NULL; printf("addr of i = %p\n", (void *)&i); printf("addr of p = %p\n", &p); printf("value of p = %p\n", p); printf("size of p = %ld\n", sizeof(p)); p = &i; printf("addr of i = %p\n", (void *)&i); printf("addr of p = %p\n", &p); printf("value of p = %p\n", p); return(0);}~ gcc -g -c aa.c gcc -g -o aa aa.o ./aa addr of i = 0x7fff7e04c044addr of p = 0x7fff7e04c048value of p = (nil)size of p = 8addr of i = 0x7fff7e04c044addr of p = 0x7fff7e04c048value of p = 0x7fff7e04c044
0 0
- C point and array practice
- The practice program of C on point
- Array & Pointer & function call practice and result
- C and point lessen 1
- c pointer and array
- c++<vector>AND<array>
- Point And Array你不知道的事
- Point And Array你不知道的事2
- array and pointer in c
- ousahayashi's array practice!
- Matrix Problem : Array Practice
- 《Programming: Principles and Practice Using C++》读书笔记(一)
- Kickstart Practice Round 2017 Problem C. Sherlock and Parentheses
- Codeforces 718C C. Sasha and Array
- c point
- point C
- C#note 04: array and collections
- Array vector string and C str
- C++ 检测内存泄露工具 -- Windows平台
- JSONKit报错
- OpenCV3.1+numpy1.10.4+ubuntu14.04 x86_64:
- linux中的libz.so.1库文件丢失解决办法
- 项目总结二:龙图OA项目总结
- C point and array practice
- 从头认识Spring-1.2 什么是AOP?为什么需要面向切面编程?
- Docker镜像和容器系列(二)- 操作详解
- IOS CALayer 详解
- Spring 事务
- uva11636
- MFC之CDC的结构类图
- iOS进阶7--桥接JS和Native
- (转)UEFI概述