C Programming

prev next

Practise Exercise 9: Structures

1. A structure called record which holds an integer called loop, a character array of 5 elements called word, and a float called sum, looks like

Structure 1

	struct record { 
		int loop;
		char word[5];
		float sum;
	};
Structure 2

	type structure record { 
		loop : integer;
		word : array[0..4] of char;
		sum : real;
	};
Structure 3

	type record { 
		integer loop;
		char word[4];
		float sum;
	}

2. The statement which declares a structure variable called sample, defined from a structure of type struct record, is

type sample : record;
struct sample;
struct record sample;
declare sample as type record;

3. The statment that assigns the value 10 to the field loop of the sample structure (which is of type struct record), is

loop = 10;
sample.loop = 10;
record.sample.loop = 10;
record.loop = 10;

4. The statement that prints out (using printf) the value of the word array of the sample structure is

printf("%d", sample);
printf("%s", word );
printf("%c", sample-word );
printf("%s", sample.word );

5. The correct definition for a structure called birthdays, whose fields are a structure of type struct time called btime, and a structure of type struct date, called bdate, is

Structure 1

	birthdays {
		time btime;
		date bdate;
	};
Structure 2

	struct birthdays {
		struct time btime;
		struct date bdate;
	};
Structure 3

	struct birthdays {
		struct bdate date;
		struct btime time;
	};

©Copyright B Brown. 1984-1999. All rights reserved.
prev next