Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |