mytest.c 828 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. int
  8. recursive(int a)
  9. {
  10. if (a > 0) {
  11. return recursive(a - 1) + 1;
  12. }
  13. else
  14. return 0;
  15. }
  16. int
  17. testFunction(int *input, int length)
  18. {
  19. int sum = 0;
  20. for (int i = 0; i < length; ++i) {
  21. sum += input[i];
  22. }
  23. return sum;
  24. }
  25. int
  26. main(int argc, char **argv)
  27. {
  28. int arr[5] = { 1, 2, 3, 4, 5 };
  29. testFunction(arr, recursive(5));
  30. char *buf;
  31. printf("Hello world!\n");
  32. buf = malloc(1024);
  33. if (!buf) {
  34. printf("malloc buf failed\n");
  35. return -1;
  36. }
  37. printf("buf ptr: %p\n", buf);
  38. snprintf(buf, 1024, "%s", "1234\n");
  39. printf("buf: %s", buf);
  40. free(buf);
  41. return 0;
  42. }