Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct point{
- int x;
- int y;
- };
- struct rect {
- struct point p1;
- struct point p2;
- };
- /*
- typedef struct{
- float x;
- float y;
- float z;
- }Vert;
- */
- typedef struct vert{
- float x;
- float y;
- float z;
- }Vert;
- struct point testas1(int x, int y)
- {
- struct point sP;
- sP.x = x;
- sP.y = y;
- return sP;
- }
- struct rect testas2()
- {
- struct rect sR;
- sR.p1.x = 1;
- sR.p1.y = 2;
- struct point ptl;
- ptl.x=3;
- ptl.y=4;
- sR.p2 = ptl;
- return sR;
- }
- Vert testas3(float x, float y, float z)
- {
- Vert sV;
- sV.x = x;
- sV.y = y;
- sV.z = z;
- return sV;
- }
- int main (int argc, char **argv){
- struct point pt;
- struct rect fgr;
- Vert sVrt;
- Vert* pVrt;
- pt = testas1(1, 2);
- printf("%d %d\n", pt.x, pt.y);
- fgr = testas2();
- printf("%d %d %d %d\n", fgr.p1.x, fgr.p1.y, fgr.p2.x, fgr.p2.y);
- sVrt = testas3( 0.1 , 0.2 , 0.3 );
- printf("%f %f %f\n", sVrt.x, sVrt.y, sVrt.z);
- printf("sizeof(float):\t%zu\n", sizeof(float));
- printf("sizeof(Vert):\t%zu\n", sizeof(Vert));
- pVrt = malloc(sizeof(Vert));
- if(pVrt != NULL)
- {
- *pVrt = testas3( 0.12 , 0.22 , 0.32 );
- printf("%f %f %f\n", pVrt->x, pVrt->y, pVrt->z);
- free(pVrt);
- }
- else printf("memory allocation error.\n");
- return 0;
- }
- /*
- output:
- 1 2
- 1 2 3 4
- 0.100000 0.200000 0.300000
- sizeof(float): 4
- sizeof(Vert): 12
- 0.120000 0.220000 0.320000
- */
Advertisement
Add Comment
Please, Sign In to add comment