1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| void testDatatype() { printf("数据类型:\n"); int intValue = 1; printf("整型%d\n",intValue); char charValue = 'a'; printf("char类型:%c\n",charValue); unsigned int uintValue = 2; printf("无符号整型:%d\n",uintValue); float fValue = 3.14; double dValue = 3.14; long long lValue = 123456789; printf("float类型:%.2f\n",fValue); printf("double类型%f\n",dValue); printf("long类型:%ld\n",lValue); }
void testPointer() { int a = 10; int *p = &a; int **pp = &p; printf("\n"); printf("a value:%d\n,a address is:%p\n",a,&a); printf("p memroy address is:%p,p point address is%p, p point value is:%d\n",&p,p,*p); printf("*pp is%p, pp memroy address is:%p,pp point address value is:%p\n, pp value:%d\n",*pp, &pp, pp,**pp);
int s = 1024; int *sP = &s; *sP = 'b';
printf("s origin address:%p\n",&s); printf("sp point address:%p\n",&sP); printf("sP point target address:%p\n",sP); printf("sP point target vakye:%c\n",*sP); printf("point sieze:%d\n",sizeof(*sP)); printf("%d\n",s);
int arrayA[] = {1,2,3}; int *pA = arrayA;
printf("pA is :%d\n",*(pA+2));
int arrayB[2][3] = {{1,2,3},{4,5,6}}; int (*arrayBP)[3] = arrayB; int (*pC)[3] = arrayB; printf("arrayBP[0][2]%d\n",arrayBP[0][2]); printf("%d\n",(*(*(pC+1)+2)));
}
int testCalculate(int a, int b) { return a + b; }
void testArray() { int a[] = {1,3,5}; int b[10]; for(int i =0;i<10;i++) { b[i] = i; } int c[2][3] = {{1,2,3},{4,5,6}};
char str[] ="hello"; int charArrayLength = sizeof(str)/sizeof(str[0]); printf("%d\n",charArrayLength); printf("%d\n",sizeof(str)); for(int i=0;i<charArrayLength;i++) { printf("%c\n",str[i]); } }
char* reverseChars(char *s,int length) { printf("the length is %d",length); char *targetResult = (char *)malloc((length+1) * sizeof(char)); if (targetResult == NULL) { printf("内存分配失败"); return NULL; } for(int i=0;i<length;i++) { targetResult[i] = s[length-1-i]; }
targetResult[length] = '\0'; return targetResult; }
int main() { testDatatype(); testPointer(); int (*pSumFunc)(int,int) = testCalculate; int result = pSumFunc(10,20); printf("Sum is:%d\n",result);
int i = 0; int count = 10;
for (i = 0; i < count; i++) { printf("value is:%d \n",calculateSub(i*i,i)); } TrafficLight currentLight = YELLOW; printf("current light is:%d",currentLight);
struct Student student = {15,1,"y","p"}; struct Student student2; strcpy(student2.firstName,"p"); student2.lastName[0] = 'c'; student2.lastName[1] = 'h'; student2.lastName[2] = 'e'; printf("%s %s\n",student.firstName,student.lastName); printf("%s %s\n",student2.firstName,student2.lastName);
char *sArray = "abcdefg"; if ((sArray!=NULL)) { int sLength = strlen(sArray); char *sResult = reverseChars(sArray,sLength); printf("倒叙结果:%s\n",sResult); free(sResult); } return 0; }
|