© Slobodan Dmitrović 2021
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6643-4_44

44. Where to Use Pointers?

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 

In this chapter, we discuss several pointers use cases, including the use of pointers as function parameters.

44.1 Pointers to Existing Objects

Pointers can point to existing data objects using the address-of operator &. Example:
#include <stdio.h>
int main(void)
{
      char mychar = 'A';
      char *p = &mychar;
      printf("The pointed-to value is: %c\n", *p);
}
Output:
The pointed-to value is: A
This example defines a variable of type char and makes the pointer point at that variable/data object using the & operator. The variable’s type char is matched by pointers char *

Get Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language 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.