#include"stdafx.h"
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stddef.h>
// #include <opencv2/opencv.hpp>
#define SIZE 100
void to_binary(unsigned long);
int StrToInt(char*string);
int sum(const int*);
void copy_arr(double [], const double [], int);
void copy_ptr(double*, const double*, int);
void copy_ptrs(double [], const double [], const double *);
void show_ele(const double[], int);
int main(int, char**)
{
/*
printf("biggest int:%d\n", INT_MAX);
printf("biggest long long:%lld\n", LLONG_MAX);
printf("One byte = %d in this system\n", CHAR_BIT);
printf("biggest double:%e\n", DBL_MAX);
printf("smallest float:%e\n", FLT_MIN);
printf("float precision:%d\n", FLT_DIG);
printf("float epsilon:%e\n", FLT_EPSILON);
float n1 = 3.0;
double n2 = 3.0;
long n3 = 2000000000;
long n4 = 1234567890;
printf("%.1e, %.1e, %.1e, %.1e\n", n1, n2, n3, n4);
printf("%ld, %ld\n", n3, n4);
printf("%ld, %ld, %ld, %ld\n", n1, n2, n3, n4);
#define Q "His Halmet was funny without being vulgar."
printf("%c%c%c\n", 'H', 105, '\41');
printf("\"%s\"\nhas %d characters.\n", Q, strlen(Q));
printf("Is %2.2e the same as %2.2f?\n", 1201.0, 1201.0);
#define BOOK "War and Peace"
float cost = 12.99;
float percent = 80.0;
printf("this copy of \"%s\" sells for $%5.2f.\nThat is %2.0f%% of list.", BOOK, cost, percent);
int n = 0;
size_t intsize;
intsize = sizeof(int);
printf("n = %d, n has %zd bytes; all ints have %zd bytes.\n", n, sizeof(n), intsize);
char ch;
while((ch = getchar()) != '#')
putchar(ch);
putchar(getchar());
putchar('H');
putchar('\007');
putchar('\n');
putchar('\b');
unsigned long number;
while (scanf("%lu", &number) == 1) {
to_binary(number);
putchar('\n');
}
int a[10][3] = { 1,2,3 };
char*s = "1234567890";
int t = StrToInt(s);
printf("%d\n", t);
int a[3] = { 1,2,3 };
int *aptr = a;
printf("a = %p\n", a);
printf("&a[0] = %p\n", &a[0]);
for (int index = 0; index < 3; aptr += index) {
printf("&a[%d] = %p\n", index, aptr);
index++;
}
int n = 100;
int *ptr = &n;
printf("ptr = %p\n", ptr);
printf("&n = %p\n", &n);
printf("*ptr = %d\n", *ptr);
printf("&ptr = %p\n", &ptr);
int a[5] = { 3, 5, 7, 9, 2 };
int *aptr = a;
int total = sum(aptr);
printf("Total sum of array a = %d\n", total);
const int days[12] = { 31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 };
int rates[5] = { 31, 28, 31, 30, 31 };
const int *rptr = rates;
rates[2] = 40;
rptr++;
double rates[5] = { 88.99, 100, 87.88, 78.91, 67.99 };
const double locked[4] = { 0.08, 0.075, 0.0754, 0.07 };
const double*pc = rates;
pc = locked;
pc = &rates[3];
printf("*pc = %.2f\n", *pc);
double *pc2 = rates;
// pc2 = locked;
pc2 = &rates[3];
double * const pc3 = rates;
*pc3 = 93.2;
const double * const pc4 = rates;
int zippo[4][2];
printf("zippo = %-20p\n", zippo);
printf("&zippo[0] = %-20p\n", &zippo[0]);
printf("&zippo[0][0] = %-20p\n", &zippo[0][0]);
printf("the size of zippo = %d\n", sizeof(zippo));
printf("the size of zippo[0] = %d\n", sizeof(zippo[0]));
printf("the size of zippo[0][0] = %d\n", sizeof(zippo[0][0]));
printf("(zippo+1) - (zippo[0] + 1) = %d\n", (sizeof(zippo + 1) - sizeof(zippo[0] + 1)));
printf("(zippo+1) - (zippo[0] + 1) = %d\n", (**(zippo + 1) - *(zippo[0] + 1)));
int zippo[4][2] = { {2, 4}, {6, 8}, {1, 3}, {5, 7} };
int(*zptr)[2];
zptr = zippo;
printf("zippo = %p,\tzip+1 = %p\n", zippo, zippo + 1);
printf("zippo[0] = %p,\tzip[0]+1 = %p\n", zippo[0], zippo[0] + 1);
printf("*zippo = %p,\t*zip+1 = %p\n", *zippo, *zippo + 1);
printf("zippo[0][0] = %d\n", zippo[0][0]);
printf("*zippo[0] = %d\n", *zippo[0]);
printf("**zippo = %d\n", **zippo);
printf("zippo[2][1] = %d\n", zippo[2][1]);
printf("*(*(zippo+2)+1) = %d\n", *(*(zippo+2)+1));
printf("==========================================================\n");
printf("zptr = %p,\tzptr+1 = %p\n", zptr, zptr + 1);
printf("zptr[0] = %p,\tzptr[0]+1 = %p\n", zptr[0], zptr[0] + 1);
printf("*zptr = %p,\t*zptr+1 = %p\n", *zptr, *zptr + 1);
printf("zptr[0][0] = %d\n", zptr[0][0]);
printf("*zptr[0] = %d\n", *zptr[0]);
printf("**zptr = %d\n", **zptr);
printf("zptr[2][1] = %d\n", zptr[2][1]);
printf("*(*(zptr+2)+1) = %d\n", *(*(zptr + 2) + 1));
double source[5] = { 1.1, 2.2, 3.3, 4.4, 5.5 };
double t1[5];
double t2[5];
double t3[5];
copy_arr(t1, source, 5);
printf("t1\n");
show_ele(t1, 5);
double *t1_ptr = t1;
double *t2_ptr = t2;
copy_ptr(t2_ptr, t1_ptr, 5);
printf("t2\n");
show_ele(t2, 5);
double *t3_ptr = t3 + 4;
copy_ptrs(t3, source, t3_ptr);
printf("t3\n");
show_ele(t3, 5);
char words[SIZE];
puts("Enter a string, Please.");
gets_s(words);
puts(words);
puts("Done!");
*/
char dont[] = { 'W', 'O', 'W', '!' };
// char side_a[] = "Side A";
// char side_b[] = "SIde B";
puts(dont);
return 0;
}
void copy_arr(double target[], const double source[], int n) {
int i;
for (i = 0; i < n; i++) {
target[i] = source[i];
// printf("target[%d] = %.1f ", i, target[i]);
}
}
void copy_ptr(double*target, const double*source, int n) {
int i;
for (i = 0; i < n; i++)
*target++ = *source++;
}
void copy_ptrs(double target[], const double source[], const double *p) {
double *tptr = target;
const double *sptr = source;
for (; sptr <= p; sptr++, tptr++)
*tptr = *sptr;
}
void show_ele(const double arr[], int n) {
for (int i = 0; i < n; i++) {
printf("arr[%d] = %.1f\t", i, arr[i]);
}
printf("\n");
}
void to_binary(unsigned long n) {
int r;
r = n % 2;
if (n > 0)
to_binary(n / 2);
putchar(r == 0 ? '0' : '1');
}
int StrToInt(char*string) {
int number = 0;
if (string == NULL)
return -1;
while (*string != 0) {
number = number * 10 + *string - '0';
++string;
}
return number;
}
int sum(const int*arr) {
int sum = 0;
if (arr == NULL) {
printf("Your arrray is NULL!\n");
return -1;
}
for (int i = 0; i < 5; i++)
sum += *arr++;
return sum;
}
C语言小练习--指针数组等
最新推荐文章于 2021-12-04 16:02:24 发布