Dev - C++ - Alguien que me explique lo que hace este codigo!!!

 
Vista:

Alguien que me explique lo que hace este codigo!!!

Publicado por Dulce Esmeralda (2 intervenciones) el 01/11/2005 00:07:06
Hola a todos... resulta que yo vi C++ en 2 semestres de mi carrera, los primero dos para ser exacta... y ahorita me topo con este codigo de C++ y no me acuerdo de nada!!!... ya investigue pero no me quedan totalmente claras las cosas...
Alguien que me ayude por favor y me diga lo que hace este codigo...

Muchas gracias de antemano.

#include <stdio.h>

typedef struct employee_st {
char name[40];
int id;
} Employee;

int main()
{
int myInt;
Employee john;

printf("Size of int is %d\n",sizeof(myInt)); -- 4
/* The argument of sizeof is an object */
printf("Size of int is %d\n",sizeof(int)); 4
/* The argument of sizeof is a data type */

printf("Size of Employee is %d\n",sizeof(Employee)); 44
/* The argument of sizeof is an object */
printf("Size of john is %d\n",sizeof(john)); 44
/* The argument of sizeof is a data type */

printf("Size of char is %d\n",sizeof(char)); 1
printf("Size of short is %d\n",sizeof(short)); 2
printf("Size of int is %d\n",sizeof(float)); 4
printf("Size of int is %d\n",sizeof(double)); 8

}



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{

Employee *workers, *wpt;
int num;

printf("How many employees do you want\n");
scanf("%d",&num);

workers = (Employee *) malloc(num * sizeof(Employee));
if (workers == NULL)
{
printf("Unable to allocated space for employees\n");
return 1;
/* A nonzero return is usually used to indicate an error */
}

wpt = workers;

strcpy(wpt->name,"John");
wpt->id = 12345;

wpt++;
strcpy(wpt->name,"Justin");
wpt->id = 12346;

wpt = workers;
printf("Employee %d is %s\n", wpt->id, wpt->name);
wpt++;
printf("Employee %d is %s\n", wpt->id, wpt->name);

free(workers);
workers = NULL;

return 0;
}


Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder