C exercises: Pointers, character arrays, and standard I/O exercises
- Write a single statement or set of statements
to accomplish each of the following:
- Define a structure called part containing an
int variable
partNumber, and char array partName whose values
may be as long as 25 characters.
- Define Part to be a synonym for the type struct part.
- Use Part to declare variable a to be of type
struct part,
array b[10] to be of type struct part, and variable
ptr to be of type pointer to struct part.
- Read a part number and a part name from the keyboard into the
individual members of variable a.
- Assign the member values of variable a
to element 3 of array b.
- Assign the address of array b to the pointer variable ptr.
- Print the members values of element 3 of array b to the
display using the variable ptr
and the structure pointer operator to refer to the members.
-
Assume the following variables have been declared as shown.
double number1 = 7.3, number2;
char* ptr = NULL;
char s1[100], s2[100];
- Declare the variable dPtr to be a pointer to a variable
of type double.
- Assign the address of variable number1 to pointer variable dPtr.
- Print the value of the variable pointed to by dPtr to the
display.
- Assign the value of the variable pointed to by dPtr
to variable number2.
- Print the value of number2 to the display.
- Print the address of number1 to the display.
- Print the address stored in dPtr to the display.
- Is the value printed the equal to the address of number1?
- Copy the string stored in character array s1 into character array s2.
- Compare the string stored in character array s1 with
the string in character array s2, and print the result to the display.
- Append the string in character array s2
to the string in character array s1.
Will this cause a run-time error?
- Determine the length of the string stored in character array s1,
and print the result to the display.
|