Skip to main content

Working with Arrays

  • Chapter
  • First Online:
Pointers in C Programming
  • 1787 Accesses

Abstract

Enough about general considerations for arrays and pointers—it is time we see how we use both in practice. I will start by showing a few examples of how we can solve some selected problems using both arrays and pointers and illustrate how closely related the two things are. Quite often, the code you write to operate on an array is the same as the code you write to operate on pointers, even when you do not use pointers plus offsets (which is, after all, exactly what we do when we use the array syntax). In an attempt to make it at least appear that we are working with two different types of objects, I will use different conventions for the functions in this section. Functions with array arguments will have the type

rettype function(int n, type array[n]);

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 64.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The static_assert macro was introduced in C11, so if your compiler doesn’t support it, just delete the line. It is unlikely that your integer type should have an odd size.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2021 Thomas Mailund

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Mailund, T. (2021). Working with Arrays. In: Pointers in C Programming. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-6927-5_6

Download citation

Publish with us

Policies and ethics