Learn How to Program in Cby Dr. Kristin Switala
|
|
Review: Variables (d)
Instructions: Think about each question and write the answer in your notebook.
General Questions
1. What format specifier do we use with characters?
2. What format specifier do we use with strings?
3. What does ASCII mean?
4. Why do we use \0 or NULL?
White Box Testing
1. Fix the errors in this C source code. There are 2 errors.
|
#include <stdio.h>
void main( )
{
char first
printf("\nType the first letter of your name: ");
scanf("%c", first);
printf("\nThe numeric value of your initial %c is %d.\n", first, first);
}
|
2. Fix the errors in this C source code. There are 4 errors.
|
#include <stdio.h>
void main( )
{
char name = "Louise Boyd";
char place[ ] = North Pole;
int year = 1955;
int birth = 1887;
int age;
printf("\n%d was a great explorer of the %s.", name, place);
printf("\nIn %d she was the first woman to fly over the %s.", year, place);
age = year - birth;
printf("\n%s was %s years old.", name, age);
}
|
|
|