Write instructions using typedef to define the following types in C:
- byte as an unsigned int
- vector as an array of N elements
- boolean as an enumaration of 0 or 1
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
#define N 100
typedef unsigned char byte; /* Definition of byte */
typedef int vector[N]; /* Vector is an array of N elements */
/* Enumeration to define the boolean type */
typedef enum {FALSE = 0, TRUE = 1} boolean;
main()
{
byte b;
int i;
vector v;
for (b = 1; b < 300; b++) /* infinite loop since b never */
printf("i: %i\n", b); /* reaches 300 */
for (i = 1; i < N; i++)
v[i] = i;
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Distance between two points