Chapter 5Writing and Testing Programs

DOI: 10.1201/9781003257981-5

This chapter uses programming problems to illustrate how to use pointers and how to use tools for testing programs. This chapter teaches the following important concepts:

  • Understand the differences between function declarations and definitions.

  • Write programs with multiple files, compile them separately and link them together to create an executable.

  • Use the make command in Linux to build and test programs.

  • Detect memory errors using gcc -fsanitize and valgrind.

  • Use gcov to detect untested lines.

5.1 Distinct Array Elements

This program has a function with two arguments: an array of integers and the number of array elements. The function returns 1 if the array elements are ...

Get Intermediate C Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.