1.2 Pointer syntax and Null Pointers


Pointer Syntax

Pointers store the addresses of variables, so the first step to declaring a pointer is to have a variable.
int var = 9;
After you declare your variable, it’s time to make a pointer. Pointers must be the same data type as the variable they are storing. In simple terms, if I’m storing the address of an int in my pointer, I can’t use char. After you have the data type, add an asterisk (*) next to it. Then, give your pointer a name, but not the same one as your variable. Finally, set the pointer equal to &variable_name.
int var = 9; int *ptr = &var;

Previous Section

Next Section

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.