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 | void str_print( char *str ) { int i; for ( i = 0; i < strlen ( str ); i++ ) { printf("%c",str[ i ] ); } } void str_print1 ( char *str ) { int len; len = strlen ( str ); for ( i = 0; i < len; i++ ) { printf("%c",str[ i ] ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | int multiply ( int *num1 , int *num2 ) { *num1 = *num2; *num1 += *num2; return *num1; } int multiply1 ( int *num1 , int *num2 ) { *num1 = 2 * *num2; return *num1; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | struct { char c; int i; short s; }str_1; struct { char c; short s; int i; }str_2; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | int x = 4; if ( x = 1 ) { x = x + 2; printf("%d",x); // Output is 3 } int x = 4; if ( 1 = x ) { x = x + 2; printf("%d",x); // Compilation error } |
1 2 3 4 5 6 7 | typedef int* INT_PTR; INT_PTR a , b; # define INT_PTR int*; INT_PTR a , b; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /*first_file.c*/ static int foo ( int a ) { /*Whatever you want to in the function*/ } /*second_file.c*/ int foo ( int ) int main() { foo(); // This is not a valid function call as the function foo can only be called by any other function within first_file.c where it is defined. return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | int fib ( n ) { if ( n == 0 || n == 1 ) { return 1; } else { return fib( n - 2 ) + fib ( n - 1 ); } } |
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 | int calc_fib ( int n ) { int val[ n ] , i; for ( i = 0; i <=n; i++ ) { val[ i ] = -1; // Value of the first n + 1 terms of the fibonacci terms set to -1 } val[ 0 ] = 1; // Value of fib ( 0 ) is set to 1 val[ 1 ] = 1; // Value of fib ( 1 ) is set to 1 return fib( n , val ); } int fib( int n , int* value ) { if ( value[ n ] != -1 ) { return value[ n ]; // Using memoization } else { value[ n ] = fib( n - 2 , value ) + fib ( n - 1 , value ); // Computing the fibonacci term } return value[ n ]; // Returning the value } |
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 | void dangling_example() { int *dp = malloc ( sizeof ( int )); /*........*/ free( dp ); // dp is now a dangling pointer dp = NULL; // dp is no longer a dangling pointer } void wild_example() { int *ptr; // Uninitialized pointer printf("%u"\n",ptr ); printf("%d",*ptr ); } |
欢迎光临 openKylin论坛 (https://forum.openkylin.top/) | Powered by Discuz! X3.3 |