notes/education/software development/ECE1400/Chapter 14 Exercises.md

50 lines
1002 B
Markdown
Raw Permalink Normal View History

2024-11-05 18:28:09 +00:00
> **12.** Suppose that the macro `M` has been defined as follows:
```c
#define M 10
```
> Which of the following tests will fail?
```c
// C will fail, because `M` is defined.
#ifndef M
2024-11-05 18:33:13 +00:00
// E will fail, because `M` is defined
#if !defined(M)
2024-11-05 18:28:09 +00:00
```
---
2024-11-05 18:23:09 +00:00
> **13.** Show what the following program will look like after preprocessing. You may ignore any lines added to the program as a result of including the `<stdio.h>` header.
2024-11-05 18:38:30 +00:00
```c
#include <stdio.h>
int main(void)
{
f();
}
void f(void) {
printf("N is %d\n", 100);
}
```
---
> **15.** Suppose that a program needs to display messages in either English, French, or Spanish. Using conditional compilation, write a program fragment that displays one of the following three messages, depending on whether or not the specified macro is defined.
```c
2024-11-05 18:43:30 +00:00
#ifdef ENGLISH
#define MESSAGE "Insert Disk 1"
#endif
2024-11-05 18:38:30 +00:00
2024-11-05 18:43:30 +00:00
#ifdef FRENCH
#define MESSAGE "Inserez Le Disque 1"
#endif
2024-11-05 18:38:30 +00:00
2024-11-05 18:43:30 +00:00
#ifdef SPANISH
#define MESSAGE "Inserte El Disco 1"
#endif
printf(MESSAGE);
2024-11-05 18:38:30 +00:00
```