Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Pointers | Pointers
C Basics
course content

Зміст курсу

C Basics

C Basics

1. Introduction
2. Data
3. Operators
4. Control Statements
5. Functions
6. Pointers

Pointers

Using the reference operator & and the dereference operator *, we can create and work with pointers.

A pointer is a data type, just like int, char, or double. The pointer is designed to store an address, which you can obtain using the & operator. To declare a pointer, prepend it with the * character.

In essence, a pointer is a variable that holds the address of another object.

Note

Typically, pointers are named by prefixing the letter p to the name of the object they're pointing to.

When you dereference a pointer, you access the value of the variable it points to.

c

Main

copy
1234567891011121314
#include <stdio.h> int main() { int x = 22543; // variable int* pX = &x; // `pX` is pointer to `x` printf("The value of `pX` is %p\n", pX); // value of pointer `pX` printf("The value of `x` by pointer `pX` is %d\n", *pX); // pointer dereference return 0; }

Note

*(&variable) == *pVariable

If you attempt to dereference a null pointer, the compiler will raise an error:

Example provided to showcase the mistake

c

Main

copy
12345678910
#include <stdio.h> int main() { int* pX; printf("x = %p", pX); return 0; }

Завдання

Determine the size of int and double pointers.

Завдання

Determine the size of int and double pointers.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 6. Розділ 3
toggle bottom row

Pointers

Using the reference operator & and the dereference operator *, we can create and work with pointers.

A pointer is a data type, just like int, char, or double. The pointer is designed to store an address, which you can obtain using the & operator. To declare a pointer, prepend it with the * character.

In essence, a pointer is a variable that holds the address of another object.

Note

Typically, pointers are named by prefixing the letter p to the name of the object they're pointing to.

When you dereference a pointer, you access the value of the variable it points to.

c

Main

copy
1234567891011121314
#include <stdio.h> int main() { int x = 22543; // variable int* pX = &x; // `pX` is pointer to `x` printf("The value of `pX` is %p\n", pX); // value of pointer `pX` printf("The value of `x` by pointer `pX` is %d\n", *pX); // pointer dereference return 0; }

Note

*(&variable) == *pVariable

If you attempt to dereference a null pointer, the compiler will raise an error:

Example provided to showcase the mistake

c

Main

copy
12345678910
#include <stdio.h> int main() { int* pX; printf("x = %p", pX); return 0; }

Завдання

Determine the size of int and double pointers.

Завдання

Determine the size of int and double pointers.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 6. Розділ 3
toggle bottom row

Pointers

Using the reference operator & and the dereference operator *, we can create and work with pointers.

A pointer is a data type, just like int, char, or double. The pointer is designed to store an address, which you can obtain using the & operator. To declare a pointer, prepend it with the * character.

In essence, a pointer is a variable that holds the address of another object.

Note

Typically, pointers are named by prefixing the letter p to the name of the object they're pointing to.

When you dereference a pointer, you access the value of the variable it points to.

c

Main

copy
1234567891011121314
#include <stdio.h> int main() { int x = 22543; // variable int* pX = &x; // `pX` is pointer to `x` printf("The value of `pX` is %p\n", pX); // value of pointer `pX` printf("The value of `x` by pointer `pX` is %d\n", *pX); // pointer dereference return 0; }

Note

*(&variable) == *pVariable

If you attempt to dereference a null pointer, the compiler will raise an error:

Example provided to showcase the mistake

c

Main

copy
12345678910
#include <stdio.h> int main() { int* pX; printf("x = %p", pX); return 0; }

Завдання

Determine the size of int and double pointers.

Завдання

Determine the size of int and double pointers.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Using the reference operator & and the dereference operator *, we can create and work with pointers.

A pointer is a data type, just like int, char, or double. The pointer is designed to store an address, which you can obtain using the & operator. To declare a pointer, prepend it with the * character.

In essence, a pointer is a variable that holds the address of another object.

Note

Typically, pointers are named by prefixing the letter p to the name of the object they're pointing to.

When you dereference a pointer, you access the value of the variable it points to.

c

Main

copy
1234567891011121314
#include <stdio.h> int main() { int x = 22543; // variable int* pX = &x; // `pX` is pointer to `x` printf("The value of `pX` is %p\n", pX); // value of pointer `pX` printf("The value of `x` by pointer `pX` is %d\n", *pX); // pointer dereference return 0; }

Note

*(&variable) == *pVariable

If you attempt to dereference a null pointer, the compiler will raise an error:

Example provided to showcase the mistake

c

Main

copy
12345678910
#include <stdio.h> int main() { int* pX; printf("x = %p", pX); return 0; }

Завдання

Determine the size of int and double pointers.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 6. Розділ 3
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt