Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main(){
  5. int v[] = [0, 1, 2];
  6. int *p = v; //pentru a incepe de la capat pana la 0 --> int *p = v+2;
  7. printf("%d/n", *p);
  8. p = p + 1;
  9. printf("%d/n", *p);
  10. p = p + 1;
  11. printf("%d/n", *p);
  12.  
  13. return 0;
  14. }
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18.  
  19. void swap(int *x, int *y){
  20. int c = *x;
  21. *x = *y;
  22. *y = c;
  23. }
  24.  
  25. int main(){
  26. int a=3;
  27. int b=1;
  28. swap(&a, &b);
  29. printf("%d,%d/n", a, b);
  30. return 0;
  31. }
  32.  
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35.  
  36. //type * functie(...);
  37. int* allocateArray(int size, int value){
  38. int* array=(int*)malloc(size*sizeof(int));
  39. for(int i = 0; i<size; i++){
  40. array[i]=value;
  41. }
  42. return array;
  43. }
  44.  
  45. int main(){
  46. int* vector = allocateArray(5, 45);
  47. for(int j = 0; j<5; j++){
  48. printf("%f\n",vector[i]);
  49. }
  50.  
  51. free(vector);
  52. return 0;
  53. }
  54.  
  55. #include <stdlib.h>
  56. #include <stdio.h>
  57.  
  58. //Return type (*functie)(type-ul parametrilor);
  59. int (*fptr)(int);
  60. //typedef int (*fptr)(int);
  61.  
  62. int square(int num){
  63. return num*num;
  64. }
  65.  
  66. int main(){
  67. int x = 5;
  68. fptr = square;
  69. printf("return:%d, square: %d/n", x, fptr(x));
  70. return 0;
  71. }
  72.  
  73. // fct de adunare, si scadere si va returna un int si va avea 2 param primiti
  74. #include <stdlib.h>
  75. #include <stdio.h>
  76.  
  77. //Return type (*functie)(type-ul parametrilor);
  78. typedef int (*fptr)(int, int);
  79. int compute(&ptr operation, int n1, int n2){
  80. return operation(n1, n2);
  81. }
  82.  
  83. int add(int a, int b) return a+b;
  84.  
  85. int dif(int a, int b) return a-b;
  86.  
  87. int main(){
  88. fptr = compute;
  89. printf("return:%d, square: %d/n", fptr(add, 5, 6), fptr(dif, 5, 6));
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement