Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

..

  • Loading branch information...
commit bfe7a781231b5b4af300b7a29247bb5d674f638d 1 parent 22cdb64
@youngsterxyf authored
View
12 CC++/assertSample.c
@@ -0,0 +1,12 @@
+#include <assert.h>
+#include <stdio.h>
+
+int main()
+{
+ int a = 12;
+ int b = 24;
+ assert(a > b);
+ printf("a is larger than b!");
+
+ return 0;
+}
View
27 CC++/fseekSample.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+long filesize(FILE *stream);
+
+int main(void)
+{
+ FILE *stream;
+
+ stream = fopen("MyFile.txt", "w+");
+ fprintf(stream, "This is a test");
+ printf("FileSize of MyFile.txt is %ld bytes\n", filesize(stream));
+ fclose(stream);
+
+ return 0;
+}
+
+long filesize(FILE *stream)
+{
+ long curpos, length;
+
+ curpos = ftell(stream);
+ fseek(stream, 0L, SEEK_END);
+ length = ftell(stream);
+ fseek(stream, curpos, SEEK_SET);
+
+ return length;
+}
View
20 CC++/functionPointer.c
@@ -0,0 +1,20 @@
+// 验证函数指针
+#include <stdio.h>
+
+int fun(int x)
+{
+ return x + 5;
+}
+
+int main()
+{
+ int (*f)(int x) = &fun;
+ int result = f(5);
+
+ printf("Result: %d\n", result);
+ printf("The address of fun: %d\n", fun);
+ printf("The address of &fun: %d\n", &fun);
+ printf("The address of fun + 1: %d\n", fun + 1);
+ printf("The address of &fun + 1: %d\n", &fun + 1);
+ return 0;
+}
View
12 CC++/limitsSample.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <limits.h>
+
+int main()
+{
+ printf("CHAR_BIT: %d\n", CHAR_BIT);
+ printf("CHAR_MIN: %d\n", CHAR_MIN);
+ printf("CHAR_MAX: %d\n", CHAR_MAX);
+ printf("INT_MIN: %d\n", INT_MIN);
+ printf("INT_MAX: %d\n", INT_MAX);
+ return 0;
+}
View
27 CC++/structPointer.c
@@ -0,0 +1,27 @@
+// 验证结构体指针
+//
+#include <stdio.h>
+
+struct sample{
+ int t;
+ char v;
+};
+
+int main()
+{
+ struct sample *sa =(struct sample *)malloc(sizeof(struct sample));
+ struct sample sb = *sa;
+ sa->t = 2;
+ sa->v = 'a';
+
+ printf("The address sa: %d\n", sa);
+ printf("The address sb: %d\n", &sb);
+ printf("%d\n", sa[0]);
+
+ int array[5] = {0,1,2,3,4};
+ printf("%d\n",*array);
+ printf("%d\n",array);
+ printf("%d\n",array[0]);
+
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.