Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POKAZIVACI
- #include <stdio.h>
- main()
- {
- short a[]={1, 4, 6, 8, 10, 12, 14, 16, 18, 20}, *p;
- p = a+4;
- printf("*p = %d\n", *p);
- printf("p = %p\n", p);
- p++;
- printf("p = %p\n", p);
- }
- ALOKACIJA MEMORIJSKOG PROSTORA
- <stdlib.h>
- 1) malloc(int) ---- pokusava da pronadje slobodnu zonu u memoriji velicine koje smo mi naveli u zagradama.
- int *p;
- p = malloc(100*sizeof(int));
- p[0] p[1] ... p[99]
- if (p == NULL)
- 2) free(p)
- 3) calloc(int, int)
- Primjer malloc
- #include <stdio.h>
- #include <stdlib.h>
- main()
- {
- int *q;
- int i, j;
- q = malloc(100*sizeof(int));
- if (q == NULL){
- printf("Nema dovoljno memorije\n");
- exit(1);
- }
- for (i = 0; i < 100; i++)
- q[i] = i * i + 10;
- for (i = 0; i < 10; i++)
- printf("*q[%d] = %d\n", i, q[i]);
- free(q);
- }
- FUNKCIJE
- tipR imeF (tip1 Arg1, tip2 Arg2, ... , tipk Argk)
- {
- ...
- }
- 1)
- #include <stdio.h>
- #include <stdlib.h>
- int min3(int a, int b, int c)
- {
- int r;
- r = a;
- if (b < a) r = b;
- if (c < a) r = c;
- return r;
- }
- main ()
- {
- int x, y, z, u;
- printf("x, y, z = ");
- scanf("%d%d%d", &x, &y, &z);
- u = min3(x, y, z);
- printf("u = %d\n", u);
- }
- 2)
- #include <stdio.h>
- #include <stdlib.h>
- int nzd(int p, int q)
- {
- int d;
- if (p < 0) p = -p;
- if (q < 0) q = -q;
- if (p == 0) return q;
- if (q == 0) return p;
- if (p < q) d = p; else d = q;
- while ((p % d != 0) || (q % d != 0)) d--;
- return d;
- }
- main()
- {
- int x, y;
- printf("x, y = ");
- scanf("%d%d", &x, &y);
- printf("nzd je: %d\n", nzd(x, y));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement