Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Pointers Brief Overview | Pointers and Structs
C Structs

bookPointers Brief Overview

To go through the following chapters, I suggest briefly repeating the pointers in the C programming language.

Note
Note

If you are not familiar with the basic skills of working with the C programming language, we recommend taking our basic C programming language course: C Basic

Dereferencing Operator

A pointer is a variable that contains the address of another object.

Dereference operator "*" returns the value stored at the address.

Declaring and initializing a pointer looks like this:

int* pName = NULL;
main.c

main.c

copy
12345678
#include <stdio.h> int main() { int* pName = NULL; printf("%p\n", pName); // `%p` is a specifier for a pointer return 0; }

Referencing Operator &

The "&" operator returns the address of an object:

main.c

main.c

copy
12345678
#include <stdio.h> int main() { int variable; printf("%p\n", &variable); return 0; }

A variable of pointer type is used to store the address, which is returned by the & operator.

int variable;
int* pVariable;
pVariable = &variable;

To "unpack" the contents at the specified address, you must use the * operator on a variable of type pointer.

main.c

main.c

copy
12345678910
#include <stdio.h> int main() { int variable = 1024; int* pVariable = &variable; printf("Address: %p\n", pVariable); // `%p` specifier for a pointer printf("Returned value by address: %d\n", *(pVariable)); // using `*` to pointer return 0; }
Tarea

Swipe to start coding

You have a product with a specific price, and you need to increase its value by a given percentage.
Your task is to implement a function that updates the product’s price using a pointer.

Inside the updatePrice function:

  1. Use the dereference operator (*) to access the current value stored in memory — for example, *price refers to 100.0.
  2. Calculate the percentage of the current price*price * percentIncrease / 100.0, which for 10% of 100.0 equals 10.0.
  3. Add this percentage to the original value to get the updated price*price = *price + (percentage part).
  4. The function doesn’t return anything — it directly modifies the value through the pointer.

Example

Initial PriceIncrease (%)Updated Price
100.010.0110.0
250.05.0262.5
80.025.0100.0

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain the difference between the * and & operators in C?

Can you give an example of how to use pointers in a function?

What are some common mistakes when working with pointers in C?

close

Awesome!

Completion rate improved to 4.17

bookPointers Brief Overview

Desliza para mostrar el menú

To go through the following chapters, I suggest briefly repeating the pointers in the C programming language.

Note
Note

If you are not familiar with the basic skills of working with the C programming language, we recommend taking our basic C programming language course: C Basic

Dereferencing Operator

A pointer is a variable that contains the address of another object.

Dereference operator "*" returns the value stored at the address.

Declaring and initializing a pointer looks like this:

int* pName = NULL;
main.c

main.c

copy
12345678
#include <stdio.h> int main() { int* pName = NULL; printf("%p\n", pName); // `%p` is a specifier for a pointer return 0; }

Referencing Operator &

The "&" operator returns the address of an object:

main.c

main.c

copy
12345678
#include <stdio.h> int main() { int variable; printf("%p\n", &variable); return 0; }

A variable of pointer type is used to store the address, which is returned by the & operator.

int variable;
int* pVariable;
pVariable = &variable;

To "unpack" the contents at the specified address, you must use the * operator on a variable of type pointer.

main.c

main.c

copy
12345678910
#include <stdio.h> int main() { int variable = 1024; int* pVariable = &variable; printf("Address: %p\n", pVariable); // `%p` specifier for a pointer printf("Returned value by address: %d\n", *(pVariable)); // using `*` to pointer return 0; }
Tarea

Swipe to start coding

You have a product with a specific price, and you need to increase its value by a given percentage.
Your task is to implement a function that updates the product’s price using a pointer.

Inside the updatePrice function:

  1. Use the dereference operator (*) to access the current value stored in memory — for example, *price refers to 100.0.
  2. Calculate the percentage of the current price*price * percentIncrease / 100.0, which for 10% of 100.0 equals 10.0.
  3. Add this percentage to the original value to get the updated price*price = *price + (percentage part).
  4. The function doesn’t return anything — it directly modifies the value through the pointer.

Example

Initial PriceIncrease (%)Updated Price
100.010.0110.0
250.05.0262.5
80.025.0100.0

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
single

single

some-alt